class PrefixBulkEditForm(BootstrapMixin, AddRemoveTagsForm, StatusBulkEditFormMixin, CustomFieldBulkEditForm): pk = forms.ModelMultipleChoiceField(queryset=Prefix.objects.all(), widget=forms.MultipleHiddenInput()) region = DynamicModelChoiceField(queryset=Region.objects.all(), required=False, to_field_name="slug") site = DynamicModelChoiceField(queryset=Site.objects.all(), required=False, query_params={"region": "$region"}) vrf = DynamicModelChoiceField( queryset=VRF.objects.all(), required=False, label="VRF", display_field="display_name", ) prefix_length = forms.IntegerField(min_value=PREFIX_LENGTH_MIN, max_value=PREFIX_LENGTH_MAX, required=False) tenant = DynamicModelChoiceField(queryset=Tenant.objects.all(), required=False) role = DynamicModelChoiceField(queryset=Role.objects.all(), required=False) is_pool = forms.NullBooleanField(required=False, widget=BulkEditNullBooleanSelect(), label="Is a pool") description = forms.CharField(max_length=100, required=False) class Meta: nullable_fields = [ "site", "vrf", "tenant", "role", "description", ]
class VMInterfaceBulkEditForm(BootstrapMixin, AddRemoveTagsForm, CustomFieldBulkEditForm): pk = forms.ModelMultipleChoiceField(queryset=VMInterface.objects.all(), widget=forms.MultipleHiddenInput()) virtual_machine = forms.ModelChoiceField( queryset=VirtualMachine.objects.all(), required=False, disabled=True, widget=forms.HiddenInput(), ) enabled = forms.NullBooleanField(required=False, widget=BulkEditNullBooleanSelect()) mtu = forms.IntegerField( required=False, min_value=INTERFACE_MTU_MIN, max_value=INTERFACE_MTU_MAX, label="MTU", ) description = forms.CharField(max_length=100, required=False) mode = forms.ChoiceField( choices=add_blank_choice(InterfaceModeChoices), required=False, widget=StaticSelect2(), ) untagged_vlan = DynamicModelChoiceField( queryset=VLAN.objects.all(), required=False, display_field="display_name", brief_mode=False, query_params={ "site_id": "null", }, ) tagged_vlans = DynamicModelMultipleChoiceField( queryset=VLAN.objects.all(), required=False, display_field="display_name", brief_mode=False, query_params={ "site_id": "null", }, ) class Meta: nullable_fields = [ "mtu", "description", ] def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) # Limit available VLANs based on the parent VirtualMachine if "virtual_machine" in self.initial: parent_obj = VirtualMachine.objects.filter(pk=self.initial["virtual_machine"]).first() site = getattr(parent_obj.cluster, "site", None) if site is not None: # Add current site to VLANs query params self.fields["untagged_vlan"].widget.add_query_param("site_id", site.pk) self.fields["tagged_vlans"].widget.add_query_param("site_id", site.pk)
class ConfigContextBulkEditForm(BootstrapMixin, BulkEditForm): pk = forms.ModelMultipleChoiceField(queryset=ConfigContext.objects.all(), widget=forms.MultipleHiddenInput) weight = forms.IntegerField(required=False, min_value=0) is_active = forms.NullBooleanField(required=False, widget=BulkEditNullBooleanSelect()) description = forms.CharField(required=False, max_length=100) class Meta: nullable_fields = [ "description", ]
class VRFBulkEditForm(BootstrapMixin, AddRemoveTagsForm, CustomFieldBulkEditForm): pk = forms.ModelMultipleChoiceField(queryset=VRF.objects.all(), widget=forms.MultipleHiddenInput()) tenant = DynamicModelChoiceField(queryset=Tenant.objects.all(), required=False) enforce_unique = forms.NullBooleanField( required=False, widget=BulkEditNullBooleanSelect(), label="Enforce unique space" ) description = forms.CharField(max_length=100, required=False) class Meta: nullable_fields = [ "tenant", "description", ]