|
|
@@ -2,6 +2,7 @@ from __future__ import unicode_literals
|
|
|
|
|
|
from django import forms
|
|
|
from django.core.exceptions import MultipleObjectsReturned
|
|
|
+from django.core.validators import MaxValueValidator, MinValueValidator
|
|
|
from django.db.models import Count
|
|
|
from taggit.forms import TagField
|
|
|
|
|
|
@@ -10,12 +11,14 @@ from extras.forms import CustomFieldForm, CustomFieldBulkEditForm, CustomFieldFi
|
|
|
from tenancy.forms import TenancyForm
|
|
|
from tenancy.models import Tenant
|
|
|
from utilities.forms import (
|
|
|
- AnnotatedMultipleChoiceField, APISelect, BootstrapMixin, BulkEditNullBooleanSelect, ChainedModelChoiceField,
|
|
|
- CSVChoiceField, ExpandableIPAddressField, FilterChoiceField, FlexibleModelChoiceField, Livesearch, ReturnURLForm,
|
|
|
- SlugField, add_blank_choice,
|
|
|
+ AnnotatedMultipleChoiceField, APISelect, BootstrapMixin, BulkEditForm, BulkEditNullBooleanSelect,
|
|
|
+ ChainedModelChoiceField, CSVChoiceField, ExpandableIPAddressField, FilterChoiceField, FlexibleModelChoiceField,
|
|
|
+ Livesearch, ReturnURLForm, SlugField, add_blank_choice,
|
|
|
)
|
|
|
from virtualization.models import VirtualMachine
|
|
|
-from .constants import IPADDRESS_ROLE_CHOICES, IPADDRESS_STATUS_CHOICES, PREFIX_STATUS_CHOICES, VLAN_STATUS_CHOICES
|
|
|
+from .constants import (
|
|
|
+ IP_PROTOCOL_CHOICES, IPADDRESS_ROLE_CHOICES, IPADDRESS_STATUS_CHOICES, PREFIX_STATUS_CHOICES, VLAN_STATUS_CHOICES,
|
|
|
+)
|
|
|
from .models import Aggregate, IPAddress, Prefix, RIR, Role, Service, VLAN, VLANGroup, VRF
|
|
|
|
|
|
IP_FAMILY_CHOICES = [
|
|
|
@@ -940,3 +943,25 @@ class ServiceForm(BootstrapMixin, forms.ModelForm):
|
|
|
)
|
|
|
else:
|
|
|
self.fields['ipaddresses'].choices = []
|
|
|
+
|
|
|
+
|
|
|
+class ServiceFilterForm(BootstrapMixin, CustomFieldFilterForm):
|
|
|
+ model = Service
|
|
|
+ q = forms.CharField(required=False, label='Search')
|
|
|
+ protocol = forms.ChoiceField(
|
|
|
+ choices=add_blank_choice(IP_PROTOCOL_CHOICES),
|
|
|
+ required=False
|
|
|
+ )
|
|
|
+ port = forms.IntegerField(
|
|
|
+ required=False
|
|
|
+ )
|
|
|
+
|
|
|
+
|
|
|
+class ServiceBulkEditForm(BootstrapMixin, BulkEditForm):
|
|
|
+ pk = forms.ModelMultipleChoiceField(queryset=Service.objects.all(), widget=forms.MultipleHiddenInput)
|
|
|
+ protocol = forms.ChoiceField(choices=add_blank_choice(IP_PROTOCOL_CHOICES), required=False)
|
|
|
+ port = forms.IntegerField(validators=[MinValueValidator(1), MaxValueValidator(65535)], required=False)
|
|
|
+ description = forms.CharField(max_length=100, required=False)
|
|
|
+
|
|
|
+ class Meta:
|
|
|
+ nullable_fields = ['site', 'group', 'tenant', 'role', 'description']
|