예제 #1
0
class RackRoleBulkEditForm(AddRemoveTagsForm, CustomFieldModelBulkEditForm):
    pk = forms.ModelMultipleChoiceField(queryset=RackRole.objects.all(),
                                        widget=forms.MultipleHiddenInput)
    color = ColorField(required=False)
    description = forms.CharField(max_length=200, required=False)

    class Meta:
        nullable_fields = ['color', 'description']
예제 #2
0
class TagBulkEditForm(BulkEditForm):
    pk = forms.ModelMultipleChoiceField(queryset=Tag.objects.all(),
                                        widget=forms.MultipleHiddenInput)
    color = ColorField(required=False)
    description = forms.CharField(max_length=200, required=False)

    class Meta:
        nullable_fields = ['description']
예제 #3
0
class DeviceRoleBulkEditForm(AddRemoveTagsForm, CustomFieldModelBulkEditForm):
    pk = forms.ModelMultipleChoiceField(queryset=DeviceRole.objects.all(),
                                        widget=forms.MultipleHiddenInput)
    color = ColorField(required=False)
    vm_role = forms.NullBooleanField(required=False,
                                     widget=BulkEditNullBooleanSelect,
                                     label='VM role')
    description = forms.CharField(max_length=200, required=False)

    class Meta:
        nullable_fields = ['color', 'description']
예제 #4
0
class RearPortFilterForm(DeviceComponentFilterForm):
    model = RearPort
    field_groups = [
        ['q', 'tag'],
        ['name', 'label', 'type', 'color'],
        ['region_id', 'site_group_id', 'site_id', 'location_id', 'device_id'],
    ]
    type = forms.MultipleChoiceField(choices=PortTypeChoices,
                                     required=False,
                                     widget=StaticSelectMultiple())
    color = ColorField(required=False)
    tag = TagFilterField(model)
예제 #5
0
class RearPortTemplateBulkEditForm(BulkEditForm):
    pk = forms.ModelMultipleChoiceField(
        queryset=RearPortTemplate.objects.all(),
        widget=forms.MultipleHiddenInput())
    label = forms.CharField(max_length=64, required=False)
    type = forms.ChoiceField(choices=add_blank_choice(PortTypeChoices),
                             required=False,
                             widget=StaticSelect())
    color = ColorField(required=False)
    description = forms.CharField(required=False)

    class Meta:
        nullable_fields = ('description', )
예제 #6
0
class CableFilterForm(BootstrapMixin, CustomFieldModelFilterForm):
    model = Cable
    field_groups = [
        ['q', 'tag'],
        ['site_id', 'rack_id', 'device_id'],
        ['type', 'status', 'color'],
        ['tenant_id'],
    ]
    q = forms.CharField(
        required=False,
        widget=forms.TextInput(attrs={'placeholder': _('All Fields')}),
        label=_('Search'))
    region_id = DynamicModelMultipleChoiceField(queryset=Region.objects.all(),
                                                required=False,
                                                label=_('Region'),
                                                fetch_trigger='open')
    site_id = DynamicModelMultipleChoiceField(
        queryset=Site.objects.all(),
        required=False,
        query_params={'region_id': '$region_id'},
        label=_('Site'),
        fetch_trigger='open')
    tenant_id = DynamicModelMultipleChoiceField(queryset=Tenant.objects.all(),
                                                required=False,
                                                label=_('Tenant'),
                                                fetch_trigger='open')
    rack_id = DynamicModelMultipleChoiceField(
        queryset=Rack.objects.all(),
        required=False,
        label=_('Rack'),
        null_option='None',
        query_params={'site_id': '$site_id'},
        fetch_trigger='open')
    type = forms.MultipleChoiceField(
        choices=add_blank_choice(CableTypeChoices),
        required=False,
        widget=StaticSelect())
    status = forms.ChoiceField(required=False,
                               choices=add_blank_choice(CableStatusChoices),
                               widget=StaticSelect())
    color = ColorField(required=False)
    device_id = DynamicModelMultipleChoiceField(queryset=Device.objects.all(),
                                                required=False,
                                                query_params={
                                                    'site_id': '$site_id',
                                                    'tenant_id': '$tenant_id',
                                                    'rack_id': '$rack_id',
                                                },
                                                label=_('Device'),
                                                fetch_trigger='open')
    tag = TagFilterField(model)
예제 #7
0
class FrontPortFilterForm(DeviceComponentFilterForm):
    field_groups = [
        ['q', 'tag'],
        ['name', 'label', 'type', 'color'],
        [
            'region_id', 'site_group_id', 'site_id', 'location_id',
            'virtual_chassis_id', 'device_id'
        ],
    ]
    model = FrontPort
    type = forms.MultipleChoiceField(label='Тип',
                                     choices=PortTypeChoices,
                                     required=False,
                                     widget=StaticSelectMultiple())
    color = ColorField(label='Цвет', required=False)
    tag = TagFilterField(model)
예제 #8
0
class CableFilterForm(TenancyFilterForm, CustomFieldModelFilterForm):
    model = Cable
    field_groups = [
        ['q', 'tag'],
        ['site_id', 'rack_id', 'device_id'],
        ['type', 'status', 'color', 'length', 'length_unit'],
        ['tenant_group_id', 'tenant_id'],
    ]
    region_id = DynamicModelMultipleChoiceField(queryset=Region.objects.all(),
                                                required=False,
                                                label='Region')
    site_id = DynamicModelMultipleChoiceField(
        queryset=Site.objects.all(),
        required=False,
        query_params={'region_id': '$region_id'},
        label='Site')
    rack_id = DynamicModelMultipleChoiceField(
        queryset=Rack.objects.all(),
        required=False,
        label='Rack',
        null_option='None',
        query_params={'site_id': '$site_id'})
    device_id = DynamicModelMultipleChoiceField(label='device_id',
                                                queryset=Device.objects.all(),
                                                required=False,
                                                query_params={
                                                    'site_id': '$site_id',
                                                    'tenant_id': '$tenant_id',
                                                    'rack_id': '$rack_id',
                                                },
                                                label='Device')
    type = forms.MultipleChoiceField(
        label='Тип',
        choices=add_blank_choice(CableTypeChoices),
        required=False,
        widget=StaticSelect())
    status = forms.ChoiceField(label='Статус',
                               required=False,
                               choices=add_blank_choice(LinkStatusChoices),
                               widget=StaticSelect())
    color = ColorField(label='Цвет', required=False)
    length = forms.IntegerField(label='Длина', required=False)
    length_unit = forms.ChoiceField(
        label='length_unit',
        choices=add_blank_choice(CableLengthUnitChoices),
        required=False)
    tag = TagFilterField(model)
예제 #9
0
class RearPortTemplateCreateForm(ComponentTemplateCreateForm):
    type = forms.ChoiceField(
        choices=PortTypeChoices,
        widget=StaticSelect(),
    )
    color = ColorField(
        required=False
    )
    positions = forms.IntegerField(
        min_value=REARPORT_POSITIONS_MIN,
        max_value=REARPORT_POSITIONS_MAX,
        initial=1,
        help_text='The number of front ports which may be mapped to each rear port'
    )
    field_order = (
        'manufacturer', 'device_type', 'name_pattern', 'label_pattern', 'type', 'color', 'positions', 'description',
    )
예제 #10
0
class CableBulkEditForm(AddRemoveTagsForm, CustomFieldModelBulkEditForm):
    pk = forms.ModelMultipleChoiceField(queryset=Cable.objects.all(),
                                        widget=forms.MultipleHiddenInput)
    type = forms.ChoiceField(choices=add_blank_choice(CableTypeChoices),
                             required=False,
                             initial='',
                             widget=StaticSelect())
    status = forms.ChoiceField(choices=add_blank_choice(LinkStatusChoices),
                               required=False,
                               widget=StaticSelect(),
                               initial='')
    tenant = DynamicModelChoiceField(queryset=Tenant.objects.all(),
                                     required=False)
    label = forms.CharField(max_length=100, required=False)
    color = ColorField(required=False)
    length = forms.DecimalField(min_value=0, required=False)
    length_unit = forms.ChoiceField(
        choices=add_blank_choice(CableLengthUnitChoices),
        required=False,
        initial='',
        widget=StaticSelect())

    class Meta:
        nullable_fields = [
            'type',
            'status',
            'tenant',
            'label',
            'color',
            'length',
        ]

    def clean(self):
        super().clean()

        # Validate length/unit
        length = self.cleaned_data.get('length')
        length_unit = self.cleaned_data.get('length_unit')
        if length and not length_unit:
            raise forms.ValidationError(
                {'length_unit': "Must specify a unit when setting length"})
예제 #11
0
class FrontPortCreateForm(ComponentCreateForm):
    model = FrontPort
    type = forms.ChoiceField(
        choices=PortTypeChoices,
        widget=StaticSelect(),
    )
    color = ColorField(required=False)
    rear_port_set = forms.MultipleChoiceField(
        choices=[],
        label='Rear ports',
        help_text=
        'Select one rear port assignment for each front port being created.',
    )
    field_order = (
        'device',
        'name_pattern',
        'label_pattern',
        'type',
        'color',
        'rear_port_set',
        'mark_connected',
        'description',
        'tags',
    )

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

        device = Device.objects.get(
            pk=self.initial.get('device') or self.data.get('device'))

        # Determine which rear port positions are occupied. These will be excluded from the list of available
        # mappings.
        occupied_port_positions = [(front_port.rear_port_id,
                                    front_port.rear_port_position)
                                   for front_port in device.frontports.all()]

        # Populate rear port choices
        choices = []
        rear_ports = RearPort.objects.filter(device=device)
        for rear_port in rear_ports:
            for i in range(1, rear_port.positions + 1):
                if (rear_port.pk, i) not in occupied_port_positions:
                    choices.append(
                        ('{}:{}'.format(rear_port.pk,
                                        i), '{}:{}'.format(rear_port.name, i)))
        self.fields['rear_port_set'].choices = choices

    def clean(self):
        super().clean()

        # Validate that the number of ports being created equals the number of selected (rear port, position) tuples
        front_port_count = len(self.cleaned_data['name_pattern'])
        rear_port_count = len(self.cleaned_data['rear_port_set'])
        if front_port_count != rear_port_count:
            raise forms.ValidationError({
                'rear_port_set':
                'The provided name pattern will create {} ports, however {} rear port assignments '
                'were selected. These counts must match.'.format(
                    front_port_count, rear_port_count)
            })

    def get_iterative_data(self, iteration):

        # Assign rear port and position from selected set
        rear_port, position = self.cleaned_data['rear_port_set'][
            iteration].split(':')

        return {
            'rear_port': int(rear_port),
            'rear_port_position': int(position),
        }