示例#1
0
class ServiceBulkEditForm(BootstrapMixin, AddRemoveTagsForm, CustomFieldModelBulkEditForm):
    pk = forms.ModelMultipleChoiceField(
        queryset=Service.objects.all(),
        widget=forms.MultipleHiddenInput()
    )
    protocol = forms.ChoiceField(
        choices=add_blank_choice(ServiceProtocolChoices),
        required=False,
        widget=StaticSelect()
    )
    ports = NumericArrayField(
        base_field=forms.IntegerField(
            min_value=SERVICE_PORT_MIN,
            max_value=SERVICE_PORT_MAX
        ),
        required=False
    )
    description = forms.CharField(
        max_length=100,
        required=False
    )

    class Meta:
        nullable_fields = [
            'description',
        ]
示例#2
0
文件: models.py 项目: xcdr/netbox
class RackReservationForm(BootstrapMixin, TenancyForm, CustomFieldModelForm):
    region = DynamicModelChoiceField(queryset=Region.objects.all(),
                                     required=False,
                                     initial_params={'sites': '$site'},
                                     fetch_trigger='open')
    site_group = DynamicModelChoiceField(queryset=SiteGroup.objects.all(),
                                         required=False,
                                         initial_params={'sites': '$site'},
                                         fetch_trigger='open')
    site = DynamicModelChoiceField(queryset=Site.objects.all(),
                                   required=False,
                                   query_params={
                                       'region_id': '$region',
                                       'group_id': '$site_group',
                                   },
                                   fetch_trigger='open')
    location = DynamicModelChoiceField(queryset=Location.objects.all(),
                                       required=False,
                                       query_params={'site_id': '$site'},
                                       fetch_trigger='open')
    rack = DynamicModelChoiceField(queryset=Rack.objects.all(),
                                   query_params={
                                       'site_id': '$site',
                                       'location_id': '$location',
                                   },
                                   fetch_trigger='open')
    units = NumericArrayField(
        base_field=forms.IntegerField(),
        help_text=
        "Comma-separated list of numeric unit IDs. A range may be specified using a hyphen."
    )
    user = forms.ModelChoiceField(queryset=User.objects.order_by('username'),
                                  widget=StaticSelect())
    tags = DynamicModelMultipleChoiceField(queryset=Tag.objects.all(),
                                           required=False,
                                           fetch_trigger='open')

    class Meta:
        model = RackReservation
        fields = [
            'region',
            'site_group',
            'site',
            'location',
            'rack',
            'units',
            'user',
            'tenant_group',
            'tenant',
            'description',
            'tags',
        ]
        fieldsets = (
            ('Reservation', ('region', 'site', 'location', 'rack', 'units',
                             'user', 'description', 'tags')),
            ('Tenancy', ('tenant_group', 'tenant')),
        )
示例#3
0
文件: models.py 项目: xcdr/netbox
class ServiceForm(BootstrapMixin, CustomFieldModelForm):
    ports = NumericArrayField(
        base_field=forms.IntegerField(min_value=SERVICE_PORT_MIN,
                                      max_value=SERVICE_PORT_MAX),
        help_text=
        "Comma-separated list of one or more port numbers. A range may be specified using a hyphen."
    )
    tags = DynamicModelMultipleChoiceField(queryset=Tag.objects.all(),
                                           required=False)

    class Meta:
        model = Service
        fields = [
            'name',
            'protocol',
            'ports',
            'ipaddresses',
            'description',
            'tags',
        ]
        help_texts = {
            'ipaddresses':
            "IP address assignment is optional. If no IPs are selected, the service is assumed to be "
            "reachable via all IPs assigned to the device.",
        }
        widgets = {
            'protocol': StaticSelect(),
            'ipaddresses': StaticSelectMultiple(),
        }

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        # Limit IP address choices to those assigned to interfaces of the parent device/VM
        if self.instance.device:
            self.fields['ipaddresses'].queryset = IPAddress.objects.filter(
                interface__in=self.instance.device.vc_interfaces().values_list(
                    'id', flat=True))
        elif self.instance.virtual_machine:
            self.fields['ipaddresses'].queryset = IPAddress.objects.filter(
                vminterface__in=self.instance.virtual_machine.interfaces.
                values_list('id', flat=True))
        else:
            self.fields['ipaddresses'].choices = []
示例#4
0
class ServiceForm(CustomFieldModelForm):
    device = DynamicModelChoiceField(
        queryset=Device.objects.all(),
        required=False
    )
    virtual_machine = DynamicModelChoiceField(
        queryset=VirtualMachine.objects.all(),
        required=False
    )
    ports = NumericArrayField(
        base_field=forms.IntegerField(
            min_value=SERVICE_PORT_MIN,
            max_value=SERVICE_PORT_MAX
        ),
        help_text="Comma-separated list of one or more port numbers. A range may be specified using a hyphen."
    )
    ipaddresses = DynamicModelMultipleChoiceField(
        queryset=IPAddress.objects.all(),
        required=False,
        label='IP Addresses',
        query_params={
            'device_id': '$device',
            'virtual_machine_id': '$virtual_machine',
        }
    )
    tags = DynamicModelMultipleChoiceField(
        queryset=Tag.objects.all(),
        required=False
    )

    class Meta:
        model = Service
        fields = [
            'device', 'virtual_machine', 'name', 'protocol', 'ports', 'ipaddresses', 'description', 'tags',
        ]
        help_texts = {
            'ipaddresses': "IP address assignment is optional. If no IPs are selected, the service is assumed to be "
                           "reachable via all IPs assigned to the device.",
        }
        widgets = {
            'protocol': StaticSelect(),
            'ipaddresses': StaticSelectMultiple(),
        }