Exemple #1
0
class CustomLinkForm(BootstrapMixin, forms.ModelForm):
    content_type = ContentTypeChoiceField(
        queryset=ContentType.objects.all(),
        limit_choices_to=FeatureQuery('custom_links'))

    class Meta:
        model = CustomLink
        fields = '__all__'
        fieldsets = (
            ('Custom Link', ('name', 'content_type', 'weight', 'group_name',
                             'button_class', 'new_window')),
            ('Templates', ('link_text', 'link_url')),
        )
        widgets = {
            'button_class': StaticSelect(),
            'link_text': forms.Textarea(attrs={'class': 'font-monospace'}),
            'link_url': forms.Textarea(attrs={'class': 'font-monospace'}),
        }
        help_texts = {
            'link_text':
            'Jinja2 template code for the link text. Reference the object as <code>{{ obj }}</code>. '
            'Links which render as empty text will not be displayed.',
            'link_url':
            'Jinja2 template code for the link URL. Reference the object as <code>{{ obj }}</code>.',
        }
Exemple #2
0
class ExportTemplateBulkEditForm(BulkEditForm):
    pk = forms.ModelMultipleChoiceField(
        queryset=ExportTemplate.objects.all(),
        widget=forms.MultipleHiddenInput
    )
    content_type = ContentTypeChoiceField(
        queryset=ContentType.objects.all(),
        limit_choices_to=FeatureQuery('export_templates'),
        required=False
    )
    description = forms.CharField(
        max_length=200,
        required=False
    )
    mime_type = forms.CharField(
        max_length=50,
        required=False
    )
    file_extension = forms.CharField(
        max_length=15,
        required=False
    )
    as_attachment = forms.NullBooleanField(
        required=False,
        widget=BulkEditNullBooleanSelect()
    )

    class Meta:
        nullable_fields = ['description', 'mime_type', 'file_extension']
Exemple #3
0
class CustomLinkBulkEditForm(BulkEditForm):
    pk = forms.ModelMultipleChoiceField(
        queryset=CustomLink.objects.all(),
        widget=forms.MultipleHiddenInput
    )
    content_type = ContentTypeChoiceField(
        queryset=ContentType.objects.all(),
        limit_choices_to=FeatureQuery('custom_links'),
        required=False
    )
    new_window = forms.NullBooleanField(
        required=False,
        widget=BulkEditNullBooleanSelect()
    )
    weight = forms.IntegerField(
        required=False
    )
    button_class = forms.ChoiceField(
        choices=add_blank_choice(CustomLinkButtonClassChoices),
        required=False,
        widget=StaticSelect()
    )

    class Meta:
        nullable_fields = []
Exemple #4
0
class ExportTemplateForm(forms.ModelForm):
    content_type = ContentTypeChoiceField(
        queryset=ContentType.objects.all(),
        limit_choices_to=FeatureQuery('custom_links'))

    class Meta:
        model = ExportTemplate
        exclude = []
Exemple #5
0
class CustomLinkFilterForm(FilterForm):
    field_groups = [
        ['q'],
        ['content_type', 'weight', 'new_window'],
    ]
    content_type = ContentTypeChoiceField(
        queryset=ContentType.objects.all(),
        limit_choices_to=FeatureQuery('custom_links'),
        required=False)
    weight = forms.IntegerField(required=False)
    new_window = forms.NullBooleanField(
        required=False,
        widget=StaticSelect(choices=BOOLEAN_WITH_BLANK_CHOICES))
Exemple #6
0
class ExportTemplateFilterForm(FilterForm):
    field_groups = [
        ['q'],
        ['content_type', 'mime_type', 'file_extension', 'as_attachment'],
    ]
    content_type = ContentTypeChoiceField(
        queryset=ContentType.objects.all(),
        limit_choices_to=FeatureQuery('export_templates'),
        required=False)
    mime_type = forms.CharField(required=False, label=_('MIME type'))
    file_extension = forms.CharField(required=False)
    as_attachment = forms.NullBooleanField(
        required=False,
        widget=StaticSelect(choices=BOOLEAN_WITH_BLANK_CHOICES))
Exemple #7
0
class ExportTemplateForm(BootstrapMixin, forms.ModelForm):
    content_type = ContentTypeChoiceField(
        queryset=ContentType.objects.all(),
        limit_choices_to=FeatureQuery('export_templates'))

    class Meta:
        model = ExportTemplate
        fields = '__all__'
        fieldsets = (
            ('Export Template', ('name', 'content_type', 'description')),
            ('Template', ('template_code', )),
            ('Rendering', ('mime_type', 'file_extension', 'as_attachment')),
        )
        widgets = {
            'template_code': forms.Textarea(attrs={'class': 'font-monospace'}),
        }
Exemple #8
0
class CustomLinkFilterForm(BootstrapMixin, forms.Form):
    field_groups = [
        ['q'],
        ['content_type', 'weight', 'new_window'],
    ]
    q = forms.CharField(
        required=False,
        widget=forms.TextInput(attrs={'placeholder': _('All Fields')}),
        label=_('Search'))
    content_type = ContentTypeChoiceField(
        queryset=ContentType.objects.all(),
        limit_choices_to=FeatureQuery('custom_fields'),
        required=False)
    weight = forms.IntegerField(required=False)
    new_window = forms.NullBooleanField(
        required=False,
        widget=StaticSelect(choices=BOOLEAN_WITH_BLANK_CHOICES))
Exemple #9
0
class ExportTemplateFilterForm(BootstrapMixin, forms.Form):
    field_groups = [
        ['q'],
        ['content_type', 'mime_type', 'file_extension', 'as_attachment'],
    ]
    q = forms.CharField(
        required=False,
        widget=forms.TextInput(attrs={'placeholder': _('All Fields')}),
        label=_('Search'))
    content_type = ContentTypeChoiceField(
        queryset=ContentType.objects.all(),
        limit_choices_to=FeatureQuery('custom_fields'),
        required=False)
    mime_type = forms.CharField(required=False, label=_('MIME type'))
    file_extension = forms.CharField(required=False)
    as_attachment = forms.NullBooleanField(
        required=False,
        widget=StaticSelect(choices=BOOLEAN_WITH_BLANK_CHOICES))
Exemple #10
0
class CustomLinkForm(forms.ModelForm):
    content_type = ContentTypeChoiceField(
        queryset=ContentType.objects.all(),
        limit_choices_to=FeatureQuery('custom_links'))

    class Meta:
        model = CustomLink
        exclude = []
        widgets = {
            'link_text': forms.Textarea,
            'link_url': forms.Textarea,
        }
        help_texts = {
            'weight':
            'A numeric weight to influence the ordering of this link among its peers. Lower weights appear '
            'first in a list.',
            'link_text':
            'Jinja2 template code for the link text. Reference the object as <code>{{ obj }}</code>. '
            'Links which render as empty text will not be displayed.',
            'link_url':
            'Jinja2 template code for the link URL. Reference the object as <code>{{ obj }}</code>.',
        }
Exemple #11
0
class VLANGroupForm(BootstrapMixin, CustomFieldModelForm):
    scope_type = ContentTypeChoiceField(
        queryset=ContentType.objects.filter(model__in=VLANGROUP_SCOPE_TYPES),
        required=False,
        widget=StaticSelect)
    region = DynamicModelChoiceField(queryset=Region.objects.all(),
                                     required=False,
                                     initial_params={'sites': '$site'})
    sitegroup = DynamicModelChoiceField(queryset=SiteGroup.objects.all(),
                                        required=False,
                                        initial_params={'sites': '$site'},
                                        label='Site group')
    site = DynamicModelChoiceField(queryset=Site.objects.all(),
                                   required=False,
                                   initial_params={'locations': '$location'},
                                   query_params={
                                       'region_id': '$region',
                                       'group_id': '$sitegroup',
                                   })
    location = DynamicModelChoiceField(queryset=Location.objects.all(),
                                       required=False,
                                       initial_params={'racks': '$rack'},
                                       query_params={
                                           'site_id': '$site',
                                       })
    rack = DynamicModelChoiceField(queryset=Rack.objects.all(),
                                   required=False,
                                   query_params={
                                       'site_id': '$site',
                                       'location_id': '$location',
                                   })
    clustergroup = DynamicModelChoiceField(
        queryset=ClusterGroup.objects.all(),
        required=False,
        initial_params={'clusters': '$cluster'},
        label='Cluster group')
    cluster = DynamicModelChoiceField(queryset=Cluster.objects.all(),
                                      required=False,
                                      query_params={
                                          'group_id': '$clustergroup',
                                      })
    slug = SlugField()

    class Meta:
        model = VLANGroup
        fields = [
            'name',
            'slug',
            'description',
            'scope_type',
            'region',
            'sitegroup',
            'site',
            'location',
            'rack',
            'clustergroup',
            'cluster',
        ]
        fieldsets = (
            ('VLAN Group', ('name', 'slug', 'description')),
            ('Scope', ('scope_type', 'region', 'sitegroup', 'site', 'location',
                       'rack', 'clustergroup', 'cluster')),
        )
        widgets = {
            'scope_type': StaticSelect,
        }

    def __init__(self, *args, **kwargs):
        instance = kwargs.get('instance')
        initial = kwargs.get('initial', {})

        if instance is not None and instance.scope:
            initial[instance.scope_type.model] = instance.scope

            kwargs['initial'] = initial

        super().__init__(*args, **kwargs)

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

        # Assign scope based on scope_type
        if self.cleaned_data.get('scope_type'):
            scope_field = self.cleaned_data['scope_type'].model
            self.instance.scope = self.cleaned_data.get(scope_field)
        else:
            self.instance.scope_id = None