Coverage for tenancy/forms/bulk_edit.py: 100%
45 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-10 18:35 +0000
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-10 18:35 +0000
1from django import forms
2from django.utils.translation import gettext_lazy as _
4from netbox.forms import (
5 NestedGroupModelBulkEditForm,
6 NetBoxModelBulkEditForm,
7 OrganizationalModelBulkEditForm,
8 PrimaryModelBulkEditForm,
9)
10from utilities.forms import add_blank_choice
11from utilities.forms.fields import ChoiceField, DynamicModelChoiceField, DynamicModelMultipleChoiceField
12from utilities.forms.rendering import FieldSet
14from ..choices import ContactPriorityChoices
15from ..models import *
17__all__ = (
18 'ContactAssignmentBulkEditForm',
19 'ContactBulkEditForm',
20 'ContactGroupBulkEditForm',
21 'ContactRoleBulkEditForm',
22 'TenantBulkEditForm',
23 'TenantGroupBulkEditForm',
24)
27#
28# Tenants
29#
31class TenantGroupBulkEditForm(NestedGroupModelBulkEditForm):
32 parent = DynamicModelChoiceField(
33 label=_('Parent'),
34 queryset=TenantGroup.objects.all(),
35 required=False
36 )
38 model = TenantGroup
39 nullable_fields = ('parent', 'description', 'comments')
42class TenantBulkEditForm(PrimaryModelBulkEditForm):
43 group = DynamicModelChoiceField(
44 label=_('Group'),
45 queryset=TenantGroup.objects.all(),
46 required=False
47 )
49 model = Tenant
50 fieldsets = (
51 FieldSet('group', 'description'),
52 )
53 nullable_fields = ('group', 'description')
56#
57# Contacts
58#
60class ContactGroupBulkEditForm(NestedGroupModelBulkEditForm):
61 parent = DynamicModelChoiceField(
62 label=_('Parent'),
63 queryset=ContactGroup.objects.all(),
64 required=False
65 )
67 model = ContactGroup
68 fieldsets = (
69 FieldSet('parent', 'description'),
70 )
71 nullable_fields = ('parent', 'description', 'comments')
74class ContactRoleBulkEditForm(OrganizationalModelBulkEditForm):
75 model = ContactRole
76 fieldsets = (
77 FieldSet('description'),
78 )
79 nullable_fields = ('description', 'comments')
82class ContactBulkEditForm(PrimaryModelBulkEditForm):
83 add_groups = DynamicModelMultipleChoiceField(
84 label=_('Add groups'),
85 queryset=ContactGroup.objects.all(),
86 required=False
87 )
88 remove_groups = DynamicModelMultipleChoiceField(
89 label=_('Remove groups'),
90 queryset=ContactGroup.objects.all(),
91 required=False
92 )
93 title = forms.CharField(
94 label=_('Title'),
95 max_length=100,
96 required=False
97 )
98 phone = forms.CharField(
99 label=_('Phone'),
100 max_length=50,
101 required=False
102 )
103 email = forms.EmailField(
104 label=_('Email'),
105 required=False
106 )
107 address = forms.CharField(
108 label=_('Address'),
109 max_length=200,
110 required=False
111 )
112 link = forms.URLField(
113 label=_('Link'),
114 assume_scheme='https',
115 required=False
116 )
118 model = Contact
119 fieldsets = (
120 FieldSet('title', 'phone', 'email', 'address', 'link', 'description'),
121 FieldSet('add_groups', 'remove_groups', name=_('Groups')),
122 )
124 nullable_fields = (
125 'title', 'phone', 'email', 'address', 'link', 'description', 'comments'
126 )
129class ContactAssignmentBulkEditForm(NetBoxModelBulkEditForm):
130 contact = DynamicModelChoiceField(
131 label=_('Contact'),
132 queryset=Contact.objects.all(),
133 required=False
134 )
135 role = DynamicModelChoiceField(
136 label=_('Role'),
137 queryset=ContactRole.objects.all(),
138 required=False
139 )
140 priority = ChoiceField(
141 label=_('Priority'),
142 choices=add_blank_choice(ContactPriorityChoices),
143 required=False
144 )
146 model = ContactAssignment
147 fieldsets = (
148 FieldSet('contact', 'role', 'priority'),
149 )
150 nullable_fields = ('priority',)