|
| 1 | +from django.contrib.contenttypes.models import ContentType |
1 | 2 | from django.utils.translation import gettext as _
|
2 | 3 |
|
| 4 | +from extras.utils import FeatureQuery |
3 | 5 | from netbox.forms import NetBoxModelFilterSetForm
|
| 6 | +from tenancy.choices import * |
4 | 7 | from tenancy.models import *
|
5 | 8 | from tenancy.forms import ContactModelFilterForm
|
6 |
| -from utilities.forms import DynamicModelMultipleChoiceField, TagFilterField |
| 9 | +from utilities.forms.fields import ( |
| 10 | + ContentTypeMultipleChoiceField, DynamicModelMultipleChoiceField, MultipleChoiceField, TagFilterField, |
| 11 | +) |
7 | 12 |
|
8 | 13 | __all__ = (
|
| 14 | + 'ContactAssignmentFilterForm', |
9 | 15 | 'ContactFilterForm',
|
10 | 16 | 'ContactGroupFilterForm',
|
11 | 17 | 'ContactRoleFilterForm',
|
@@ -71,3 +77,36 @@ class ContactFilterForm(NetBoxModelFilterSetForm):
|
71 | 77 | label=_('Group')
|
72 | 78 | )
|
73 | 79 | tag = TagFilterField(model)
|
| 80 | + |
| 81 | + |
| 82 | +class ContactAssignmentFilterForm(NetBoxModelFilterSetForm): |
| 83 | + model = ContactAssignment |
| 84 | + fieldsets = ( |
| 85 | + (None, ('q', 'filter_id')), |
| 86 | + ('Assignment', ('content_type_id', 'group_id', 'contact_id', 'role_id', 'priority')), |
| 87 | + ) |
| 88 | + content_type_id = ContentTypeMultipleChoiceField( |
| 89 | + queryset=ContentType.objects.all(), |
| 90 | + limit_choices_to=FeatureQuery('custom_fields'), |
| 91 | + required=False, |
| 92 | + label=_('Object type') |
| 93 | + ) |
| 94 | + group_id = DynamicModelMultipleChoiceField( |
| 95 | + queryset=ContactGroup.objects.all(), |
| 96 | + required=False, |
| 97 | + label=_('Group') |
| 98 | + ) |
| 99 | + contact_id = DynamicModelMultipleChoiceField( |
| 100 | + queryset=Contact.objects.all(), |
| 101 | + required=False, |
| 102 | + label=_('Contact') |
| 103 | + ) |
| 104 | + role_id = DynamicModelMultipleChoiceField( |
| 105 | + queryset=ContactRole.objects.all(), |
| 106 | + required=False, |
| 107 | + label=_('Role') |
| 108 | + ) |
| 109 | + priority = MultipleChoiceField( |
| 110 | + choices=ContactPriorityChoices, |
| 111 | + required=False |
| 112 | + ) |
0 commit comments