1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

147 lines
3.4 KiB
Python
Raw Normal View History

2021-10-18 15:09:57 -04:00
from django import forms
2021-09-27 17:19:05 -04:00
from extras.forms import CustomFieldModelForm
from extras.models import Tag
2021-10-18 11:45:05 -04:00
from tenancy.models import *
2021-09-27 17:19:05 -04:00
from utilities.forms import (
2021-10-18 11:45:05 -04:00
BootstrapMixin, CommentField, DynamicModelChoiceField, DynamicModelMultipleChoiceField, SlugField, SmallTextarea,
2021-10-18 15:09:57 -04:00
StaticSelect,
2021-09-27 17:19:05 -04:00
)
__all__ = (
2021-10-18 15:09:57 -04:00
'ContactAssignmentForm',
2021-10-18 11:45:05 -04:00
'ContactForm',
'ContactGroupForm',
'ContactRoleForm',
2021-09-27 17:19:05 -04:00
'TenantForm',
'TenantGroupForm',
)
2021-10-18 11:45:05 -04:00
#
# Tenants
#
class TenantGroupForm(CustomFieldModelForm):
2021-09-27 17:19:05 -04:00
parent = DynamicModelChoiceField(
queryset=TenantGroup.objects.all(),
required=False
)
slug = SlugField()
tags = DynamicModelMultipleChoiceField(
queryset=Tag.objects.all(),
required=False
)
2021-09-27 17:19:05 -04:00
class Meta:
model = TenantGroup
fields = [
'parent', 'name', 'slug', 'description', 'tags',
2021-09-27 17:19:05 -04:00
]
class TenantForm(CustomFieldModelForm):
2021-09-27 17:19:05 -04:00
slug = SlugField()
group = DynamicModelChoiceField(
queryset=TenantGroup.objects.all(),
required=False
)
comments = CommentField()
tags = DynamicModelMultipleChoiceField(
queryset=Tag.objects.all(),
required=False
)
class Meta:
model = Tenant
fields = (
'name', 'slug', 'group', 'description', 'comments', 'tags',
)
fieldsets = (
('Tenant', ('name', 'slug', 'group', 'description', 'tags')),
)
2021-10-18 11:45:05 -04:00
#
# Contacts
#
class ContactGroupForm(CustomFieldModelForm):
2021-10-18 11:45:05 -04:00
parent = DynamicModelChoiceField(
queryset=ContactGroup.objects.all(),
required=False
)
slug = SlugField()
tags = DynamicModelMultipleChoiceField(
queryset=Tag.objects.all(),
required=False
)
2021-10-18 11:45:05 -04:00
class Meta:
model = ContactGroup
fields = ('parent', 'name', 'slug', 'description', 'tags')
2021-10-18 11:45:05 -04:00
class ContactRoleForm(CustomFieldModelForm):
2021-10-18 11:45:05 -04:00
slug = SlugField()
tags = DynamicModelMultipleChoiceField(
queryset=Tag.objects.all(),
required=False
)
2021-10-18 11:45:05 -04:00
class Meta:
model = ContactRole
fields = ('name', 'slug', 'description', 'tags')
2021-10-18 11:45:05 -04:00
class ContactForm(CustomFieldModelForm):
2021-10-18 11:45:05 -04:00
group = DynamicModelChoiceField(
queryset=ContactGroup.objects.all(),
required=False
)
comments = CommentField()
tags = DynamicModelMultipleChoiceField(
queryset=Tag.objects.all(),
required=False
)
class Meta:
model = Contact
fields = (
'group', 'name', 'title', 'phone', 'email', 'address', 'comments', 'tags',
)
fieldsets = (
('Contact', ('group', 'name', 'title', 'phone', 'email', 'address', 'tags')),
)
widgets = {
'address': SmallTextarea(attrs={'rows': 3}),
}
2021-10-18 15:09:57 -04:00
class ContactAssignmentForm(BootstrapMixin, forms.ModelForm):
group = DynamicModelChoiceField(
queryset=ContactGroup.objects.all(),
2021-10-18 16:20:31 -04:00
required=False,
initial_params={
'contacts': '$contact'
}
2021-10-18 15:09:57 -04:00
)
contact = DynamicModelChoiceField(
2021-10-18 16:20:31 -04:00
queryset=Contact.objects.all(),
query_params={
'group_id': '$group'
}
2021-10-18 15:09:57 -04:00
)
role = DynamicModelChoiceField(
queryset=ContactRole.objects.all()
)
class Meta:
model = ContactAssignment
fields = (
'group', 'contact', 'role', 'priority',
)
widgets = {
'priority': StaticSelect(),
}