2023-07-28 18:53:22 +05:30
|
|
|
from django.contrib.contenttypes.models import ContentType
|
2023-07-31 23:52:38 +07:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
|
|
|
|
2022-11-15 12:24:57 -05:00
|
|
|
from netbox.forms import NetBoxModelImportForm
|
2021-10-18 11:45:05 -04:00
|
|
|
from tenancy.models import *
|
2023-07-28 18:53:22 +05:30
|
|
|
from utilities.forms.fields import CSVContentTypeField, CSVModelChoiceField, SlugField
|
2021-09-27 17:19:05 -04:00
|
|
|
|
|
|
|
__all__ = (
|
2023-07-28 18:53:22 +05:30
|
|
|
'ContactAssignmentImportForm',
|
2022-11-15 12:24:57 -05:00
|
|
|
'ContactImportForm',
|
|
|
|
'ContactGroupImportForm',
|
|
|
|
'ContactRoleImportForm',
|
|
|
|
'TenantImportForm',
|
|
|
|
'TenantGroupImportForm',
|
2021-09-27 17:19:05 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2021-10-18 11:45:05 -04:00
|
|
|
#
|
|
|
|
# Tenants
|
|
|
|
#
|
|
|
|
|
2022-11-15 12:24:57 -05:00
|
|
|
class TenantGroupImportForm(NetBoxModelImportForm):
|
2021-09-27 17:19:05 -04:00
|
|
|
parent = CSVModelChoiceField(
|
2023-07-31 23:52:38 +07:00
|
|
|
label=_('Parent'),
|
2021-09-27 17:19:05 -04:00
|
|
|
queryset=TenantGroup.objects.all(),
|
|
|
|
required=False,
|
|
|
|
to_field_name='name',
|
2022-11-03 11:58:26 -07:00
|
|
|
help_text=_('Parent group')
|
2021-09-27 17:19:05 -04:00
|
|
|
)
|
|
|
|
slug = SlugField()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = TenantGroup
|
2022-11-04 07:50:43 -07:00
|
|
|
fields = ('name', 'slug', 'parent', 'description', 'tags')
|
2021-09-27 17:19:05 -04:00
|
|
|
|
|
|
|
|
2022-11-15 12:24:57 -05:00
|
|
|
class TenantImportForm(NetBoxModelImportForm):
|
2021-09-27 17:19:05 -04:00
|
|
|
slug = SlugField()
|
|
|
|
group = CSVModelChoiceField(
|
2023-07-31 23:52:38 +07:00
|
|
|
label=_('Group'),
|
2021-09-27 17:19:05 -04:00
|
|
|
queryset=TenantGroup.objects.all(),
|
|
|
|
required=False,
|
|
|
|
to_field_name='name',
|
2022-11-03 11:58:26 -07:00
|
|
|
help_text=_('Assigned group')
|
2021-09-27 17:19:05 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Tenant
|
2022-11-04 07:50:43 -07:00
|
|
|
fields = ('name', 'slug', 'group', 'description', 'comments', 'tags')
|
2021-10-18 11:45:05 -04:00
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# Contacts
|
|
|
|
#
|
|
|
|
|
2022-11-15 12:24:57 -05:00
|
|
|
class ContactGroupImportForm(NetBoxModelImportForm):
|
2021-10-18 11:45:05 -04:00
|
|
|
parent = CSVModelChoiceField(
|
2023-07-31 23:52:38 +07:00
|
|
|
label=_('Parent'),
|
2021-10-18 11:45:05 -04:00
|
|
|
queryset=ContactGroup.objects.all(),
|
|
|
|
required=False,
|
|
|
|
to_field_name='name',
|
2022-11-03 11:58:26 -07:00
|
|
|
help_text=_('Parent group')
|
2021-10-18 11:45:05 -04:00
|
|
|
)
|
|
|
|
slug = SlugField()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = ContactGroup
|
2022-11-04 07:50:43 -07:00
|
|
|
fields = ('name', 'slug', 'parent', 'description', 'tags')
|
2021-10-18 11:45:05 -04:00
|
|
|
|
|
|
|
|
2022-11-15 12:24:57 -05:00
|
|
|
class ContactRoleImportForm(NetBoxModelImportForm):
|
2021-10-18 11:45:05 -04:00
|
|
|
slug = SlugField()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = ContactRole
|
|
|
|
fields = ('name', 'slug', 'description')
|
|
|
|
|
|
|
|
|
2022-11-15 12:24:57 -05:00
|
|
|
class ContactImportForm(NetBoxModelImportForm):
|
2021-10-18 11:45:05 -04:00
|
|
|
group = CSVModelChoiceField(
|
2023-07-31 23:52:38 +07:00
|
|
|
label=_('Group'),
|
2021-10-18 11:45:05 -04:00
|
|
|
queryset=ContactGroup.objects.all(),
|
|
|
|
required=False,
|
|
|
|
to_field_name='name',
|
2022-11-03 11:58:26 -07:00
|
|
|
help_text=_('Assigned group')
|
2021-10-18 11:45:05 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Contact
|
2022-11-04 07:50:43 -07:00
|
|
|
fields = ('name', 'title', 'phone', 'email', 'address', 'link', 'group', 'description', 'comments', 'tags')
|
2023-07-28 18:53:22 +05:30
|
|
|
|
|
|
|
|
|
|
|
class ContactAssignmentImportForm(NetBoxModelImportForm):
|
2024-03-01 16:34:52 -05:00
|
|
|
object_type = CSVContentTypeField(
|
2023-07-28 18:53:22 +05:30
|
|
|
queryset=ContentType.objects.all(),
|
|
|
|
help_text=_("One or more assigned object types")
|
|
|
|
)
|
|
|
|
contact = CSVModelChoiceField(
|
|
|
|
queryset=Contact.objects.all(),
|
|
|
|
to_field_name='name',
|
|
|
|
help_text=_('Assigned contact')
|
|
|
|
)
|
|
|
|
role = CSVModelChoiceField(
|
|
|
|
queryset=ContactRole.objects.all(),
|
|
|
|
to_field_name='name',
|
|
|
|
help_text=_('Assigned role')
|
|
|
|
)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = ContactAssignment
|
2024-03-01 16:34:52 -05:00
|
|
|
fields = ('object_type', 'object_id', 'contact', 'priority', 'role')
|