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

146 lines
3.2 KiB
Python
Raw Normal View History

2021-10-18 15:09:57 -04:00
from django import forms
from netbox.forms import NetBoxModelForm
2021-10-18 11:45:05 -04:00
from tenancy.models import *
2021-09-27 17:19:05 -04:00
from utilities.forms import (
BootstrapMixin, CommentField, DynamicModelChoiceField, SlugField,
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(NetBoxModelForm):
2021-09-27 17:19:05 -04:00
parent = DynamicModelChoiceField(
queryset=TenantGroup.objects.all(),
required=False
)
slug = SlugField()
fieldsets = (
('Tenant Group', (
'parent', 'name', 'slug', 'description', 'tags',
)),
)
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(NetBoxModelForm):
2021-09-27 17:19:05 -04:00
slug = SlugField()
group = DynamicModelChoiceField(
queryset=TenantGroup.objects.all(),
required=False
)
comments = CommentField()
fieldsets = (
('Tenant', ('name', 'slug', 'group', 'description', 'tags')),
)
2021-09-27 17:19:05 -04:00
class Meta:
model = Tenant
fields = (
'name', 'slug', 'group', 'description', 'comments', 'tags',
)
2021-10-18 11:45:05 -04:00
#
# Contacts
#
class ContactGroupForm(NetBoxModelForm):
2021-10-18 11:45:05 -04:00
parent = DynamicModelChoiceField(
queryset=ContactGroup.objects.all(),
required=False
)
slug = SlugField()
fieldsets = (
('Contact Group', (
'parent', 'name', 'slug', 'description', 'tags',
)),
)
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(NetBoxModelForm):
2021-10-18 11:45:05 -04:00
slug = SlugField()
fieldsets = (
('Contact Role', (
'name', 'slug', 'description', 'tags',
)),
)
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(NetBoxModelForm):
2021-10-18 11:45:05 -04:00
group = DynamicModelChoiceField(
queryset=ContactGroup.objects.all(),
required=False
)
comments = CommentField()
fieldsets = (
('Contact', ('group', 'name', 'title', 'phone', 'email', 'address', 'link', 'description', 'tags')),
)
2021-10-18 11:45:05 -04:00
class Meta:
model = Contact
fields = (
'group', 'name', 'title', 'phone', 'email', 'address', 'link', 'description', 'comments', 'tags',
2021-10-18 11:45:05 -04:00
)
widgets = {
'address': forms.Textarea(attrs={'rows': 3}),
2021-10-18 11:45:05 -04:00
}
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 = (
'content_type', 'object_id', 'group', 'contact', 'role', 'priority',
2021-10-18 15:09:57 -04:00
)
widgets = {
'content_type': forms.HiddenInput(),
'object_id': forms.HiddenInput(),
2021-10-18 15:09:57 -04:00
}