Beispiel #1
0
class DecimalInputForm(forms.Form, BaseFormFieldPluginForm):
    """Form for ``DecimalInputPlugin``."""

    plugin_data_fields = [
        ("label", ""),
        ("name", ""),
        ("help_text", ""),
        ("initial", ""),
        ("max_digits", ""),
        ("decimal_places", ""),
        ("min_value", None),
        ("max_value", None),
        ("required", False),
        ("placeholder", ""),
    ]

    label = forms.CharField(
        label=_("Label"),
        required=True,
        widget=forms.widgets.TextInput(
            attrs={'class': theme.form_element_html_class}))
    name = forms.CharField(label=_("Name"),
                           required=True,
                           widget=forms.widgets.TextInput(
                               attrs={'class': theme.form_element_html_class}))
    help_text = forms.CharField(
        label=_("Help text"),
        required=False,
        widget=forms.widgets.Textarea(
            attrs={'class': theme.form_element_html_class}))
    initial = forms.DecimalField(
        label=_("Initial"),
        required=False,
        widget=NumberInput(attrs={'class': theme.form_element_html_class}))
    max_digits = forms.IntegerField(
        label=_("Max digits"),
        required=False,
        widget=NumberInput(attrs={'class': theme.form_element_html_class}))
    decimal_places = forms.IntegerField(
        label=_("Decimal places"),
        required=False,
        widget=NumberInput(attrs={'class': theme.form_element_html_class}))
    min_value = forms.DecimalField(
        label=_("Min value"),
        required=False,
        widget=NumberInput(attrs={'class': theme.form_element_html_class}))
    max_value = forms.DecimalField(
        label=_("Max value"),
        required=False,
        widget=NumberInput(attrs={'class': theme.form_element_html_class}))
    required = forms.BooleanField(
        label=_("Required"),
        required=False,
        widget=forms.widgets.CheckboxInput(
            attrs={'class': theme.form_element_checkbox_html_class}))
    placeholder = forms.CharField(
        label=_("Placeholder"),
        required=False,
        widget=forms.widgets.TextInput(
            attrs={'class': theme.form_element_html_class}))
Beispiel #2
0
    def get_form_field_instances(self, request=None):
        """
        Get form field instances.
        """
        widget_attrs = {
            'class': theme.form_element_html_class,
            'type': 'number',
            'placeholder': self.data.placeholder,
        }
        kwargs = {
            'label': self.data.label,
            'help_text': self.data.help_text,
            'initial': self.data.initial,
            'required': self.data.required,
        }
        if self.data.max_value:
            kwargs['max_value'] = self.data.max_value
            widget_attrs['max'] = self.data.max_value
        if self.data.min_value:
            kwargs['min_value'] = self.data.min_value
            widget_attrs['min'] = self.data.min_value

        if self.data.max_digits:
            kwargs['max_digits'] = self.data.max_digits
            widget_attrs['max'] = self.data.max_value
        if self.data.decimal_places:
            kwargs['decimal_places'] = self.data.decimal_places
            widget_attrs['min'] = self.data.min_value

        kwargs['widget'] = NumberInput(attrs=widget_attrs)

        return [(self.data.name, DecimalField, kwargs)]
Beispiel #3
0
class IPAddressInputForm(forms.Form, BaseFormFieldPluginForm):
    """Form for ``IPAddressInputPlugin``."""

    plugin_data_fields = [
        ("label", ""),
        ("name", ""),
        ("help_text", ""),
        ("initial", ""),
        ("protocol", ""),
        ("unpack_ipv4", False),
        ("max_length", "255"),
        ("required", False),
        ("placeholder", ""),
    ]

    label = forms.CharField(
        label=_("Label"),
        required=True,
        widget=forms.widgets.TextInput(
            attrs={'class': theme.form_element_html_class}))
    name = forms.CharField(label=_("Name"),
                           required=True,
                           widget=forms.widgets.TextInput(
                               attrs={'class': theme.form_element_html_class}))
    help_text = forms.CharField(
        label=_("Help text"),
        required=False,
        widget=forms.widgets.Textarea(
            attrs={'class': theme.form_element_html_class}))
    initial = forms.CharField(
        label=_("Initial"),
        required=False,
        widget=forms.widgets.TextInput(
            attrs={'class': theme.form_element_html_class}))
    protocol = forms.ChoiceField(
        label=_("Protocol"),
        choices=[(pr, pr) for pr in ip_address_validator_map.keys()],
        required=True,
        widget=forms.widgets.Select(
            attrs={'class': theme.form_element_html_class}))
    unpack_ipv4 = forms.BooleanField(
        label=_("Unpack IPV4"),
        required=False,
        widget=forms.widgets.CheckboxInput(
            attrs={'class': theme.form_element_checkbox_html_class}))
    max_length = forms.IntegerField(
        label=_("Max length"),
        required=True,
        widget=NumberInput(attrs={'class': theme.form_element_html_class}),
        initial=DEFAULT_MAX_LENGTH)
    required = forms.BooleanField(
        label=_("Required"),
        required=False,
        widget=forms.widgets.CheckboxInput(
            attrs={'class': theme.form_element_checkbox_html_class}))
    placeholder = forms.CharField(
        label=_("Placeholder"),
        required=False,
        widget=forms.widgets.TextInput(
            attrs={'class': theme.form_element_html_class}))
Beispiel #4
0
    def get_form_field_instances(self,
                                 request=None,
                                 form_entry=None,
                                 form_element_entries=None,
                                 **kwargs):
        """Get form field instances."""
        widget_attrs = {
            'class': theme.form_element_html_class,
            'type': 'number',
            'placeholder': self.data.placeholder,
        }
        field_kwargs = {
            'label': self.data.label,
            'help_text': self.data.help_text,
            'initial': self.data.initial,
            'required': self.data.required,
        }
        if self.data.max_value is not None:
            data_max_value = int(self.data.max_value)
            field_kwargs['max_value'] = data_max_value
            widget_attrs['max'] = data_max_value
        if self.data.min_value is not None:
            data_min_value = int(self.data.min_value)
            field_kwargs['min_value'] = data_min_value
            widget_attrs['min'] = data_min_value

        field_kwargs['widget'] = NumberInput(attrs=widget_attrs)

        return [(self.data.name, IntegerField, field_kwargs)]
Beispiel #5
0
class IntegerInputForm(forms.Form, BaseFormFieldPluginForm):
    """Form for ``IntegerInputPlugin``."""

    plugin_data_fields = [
        ("label", "sdlifjk"),
        ("name", "name"),
        ("help_text", "sdfm,ns"),
        ("initial", "0"),
        ("min_value", None),
        ("max_value", None),
        ("required", False),
    ]

    label = forms.CharField(
        label=_("Question text"),
        required=True,
        widget=forms.widgets.TextInput(
            attrs={'class': theme.form_element_html_class}))
    name = forms.CharField(label=_("Name"),
                           required=True,
                           widget=forms.widgets.TextInput(
                               attrs={'class': theme.form_element_html_class}))
    help_text = forms.CharField(
        label=_("Help text"),
        required=False,
        widget=forms.widgets.Textarea(
            attrs={'class': theme.form_element_html_class}))
    initial = forms.IntegerField(
        label=_("Default answer"),
        required=False,
        widget=NumberInput(attrs={'class': theme.form_element_html_class}))
    min_value = forms.IntegerField(
        label=_("Minimum value"),
        required=False,
        widget=NumberInput(attrs={'class': theme.form_element_html_class}))
    max_value = forms.IntegerField(
        label=_("Maximum value"),
        required=False,
        widget=NumberInput(attrs={'class': theme.form_element_html_class}))
    required = forms.BooleanField(
        label=_("Required"),
        required=False,
        widget=forms.widgets.CheckboxInput(
            attrs={'class': theme.form_element_checkbox_html_class}))
Beispiel #6
0
class FileInputForm(forms.Form, BaseFormFieldPluginForm):
    """Form for ``FileInputPlugin``."""

    plugin_data_fields = [("label", ""), ("name", ""), ("help_text", ""),
                          ("initial", ""),
                          ("max_length", str(DEFAULT_MAX_LENGTH)),
                          ("required", False)]

    label = forms.CharField(
        label=_("Label"),
        required=True,
        widget=forms.widgets.TextInput(
            attrs={'class': theme.form_element_html_class}))
    name = forms.CharField(label=_("Name"),
                           required=True,
                           widget=forms.widgets.TextInput(
                               attrs={'class': theme.form_element_html_class}))
    help_text = forms.CharField(
        label=_("Help text"),
        required=False,
        widget=forms.widgets.Textarea(
            attrs={'class': theme.form_element_html_class}))
    initial = forms.CharField(
        label=_("Initial"),
        required=False,
        widget=forms.widgets.TextInput(
            attrs={'class': theme.form_element_html_class}))
    max_length = forms.IntegerField(
        label=_("Max length"),
        required=True,
        widget=NumberInput(attrs={
            'class': theme.form_element_html_class,
            'min': str(DEFAULT_MIN_LENGTH)
        }),
        initial=DEFAULT_MAX_LENGTH,
        validators=[MinValueValidator(DEFAULT_MIN_LENGTH)])
    required = forms.BooleanField(
        label=_("Required"),
        required=False,
        widget=forms.widgets.CheckboxInput(
            attrs={'class': theme.form_element_checkbox_html_class}))

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

        max_length = self.cleaned_data.get('max_length', DEFAULT_MAX_LENGTH)

        if self.cleaned_data['initial']:
            len_initial = len(self.cleaned_data['initial'])
            if len_initial > max_length:
                self.add_error(
                    'initial',
                    _("Ensure this value has at most {0} characters "
                      "(it has {1}).".format(max_length, len_initial)))
Beispiel #7
0
class HoneypotInputForm(forms.Form, BaseFormFieldPluginForm):
    """Form for ``HoneypotInputPlugin``."""

    plugin_data_fields = [
        ("label", ""),
        ("name", ""),
        # ("help_text", ""),
        ("initial", ""),
        ("max_length", "255"),
        ("required", True),
        # ("placeholder", ""),
    ]

    label = forms.CharField(
        label=_("Label"),
        required=True,
        widget=forms.widgets.TextInput(
            attrs={'class': theme.form_element_html_class}
        )
    )
    name = forms.CharField(
        label=_("Name"),
        required=True,
        widget=forms.widgets.TextInput(
            attrs={'class': theme.form_element_html_class}
        )
    )
    # help_text = forms.CharField(
    #     label=_("Help text"),
    #     required=False,
    #     widget=forms.widgets.Textarea(
    #         attrs={'class': theme.form_element_html_class}
    #     )
    # )
    initial = forms.CharField(
        label=_("Initial"),
        required=False,
        widget=forms.widgets.TextInput(
            attrs={'class': theme.form_element_html_class}
        )
    )
    max_length = forms.IntegerField(
        label=_("Max length"),
        required=True,
        widget=NumberInput(attrs={'class': theme.form_element_html_class}),
        initial=DEFAULT_MAX_LENGTH
    )
    required = forms.BooleanField(
        label=_("Required"),
        required=False,
        widget=forms.widgets.CheckboxInput(
            attrs={'class': theme.form_element_checkbox_html_class}
        )
    )
class PhoneNumberForm(forms.Form, BaseFormFieldPluginForm):
    """Form for ``PhoneNumberPlugin``."""

    plugin_data_fields = [
        ("label", ""),
        ("name", ""),
        ("help_text", ""),
        ("initial", ""),
        ("max_length", "255"),
        ("required", True),
        ("placeholder", ""),
    ]

    label = forms.CharField(
        label=_("Label"),
        required=True,
        widget=forms.widgets.TextInput(
            attrs={'class': theme.form_element_html_class}))
    name = forms.CharField(label=_("Name"),
                           required=True,
                           widget=forms.widgets.TextInput(
                               attrs={'class': theme.form_element_html_class}))
    help_text = forms.CharField(
        label=_("Help text"),
        required=False,
        widget=forms.widgets.Textarea(
            attrs={'class': theme.form_element_html_class}))
    initial = forms.CharField(
        label=_("Initial"),
        required=False,
        widget=forms.widgets.TextInput(
            attrs={'class': theme.form_element_html_class}))
    max_length = forms.IntegerField(
        label=_("Max length"),
        required=True,
        widget=NumberInput(attrs={
            'class': theme.form_element_html_class,
            'min': str(DEFAULT_MIN_LENGTH)
        }),
        initial=DEFAULT_MAX_LENGTH,
        validators=[MinValueValidator(DEFAULT_MIN_LENGTH)])
    required = forms.BooleanField(
        label=_("Required"),
        required=False,
        widget=forms.widgets.CheckboxInput(
            attrs={'class': theme.form_element_checkbox_html_class}))
    placeholder = forms.CharField(
        label=_("Placeholder"),
        required=False,
        widget=forms.widgets.TextInput(
            attrs={'class': theme.form_element_html_class}))
Beispiel #9
0
class SelectMultipleWithMaxInputForm(forms.Form, BaseFormFieldPluginForm):
    """Form for ``SelectMultipleWithMaxInputPlugin``."""

    plugin_data_fields = [("label", ""), ("name", ""), ("choices", ""),
                          ("help_text", ""), ("initial", ""),
                          ("required", False), ("max_choices", "")]

    label = forms.CharField(
        label=_("Question text"),
        required=True,
        widget=forms.widgets.TextInput(
            attrs={'class': theme.form_element_html_class}))
    name = forms.CharField(label=_("Name"),
                           required=True,
                           widget=forms.widgets.TextInput(
                               attrs={'class': theme.form_element_html_class}))
    choices = forms.CharField(
        label=_("Choices"),
        required=False,
        help_text=_("Enter single choice option per line. Example:<br/>"
                    "<code>Not at all familiar<br/>"
                    "Slightly familiar<br/>"
                    "Somewhat familiar<br/>"
                    "Moderately familiar<br/>"
                    "Extremely familiar<br/></code>"),
        widget=forms.widgets.Textarea(
            attrs={'class': theme.form_element_html_class}))
    help_text = forms.CharField(
        label=_("Help text"),
        required=False,
        widget=forms.widgets.Textarea(
            attrs={'class': theme.form_element_html_class}))
    initial = forms.CharField(
        label=_("Initial"),
        required=False,
        widget=forms.widgets.TextInput(
            attrs={'class': theme.form_element_html_class}))
    required = forms.BooleanField(
        label=_("Required"),
        required=False,
        widget=forms.widgets.CheckboxInput(
            attrs={'class': theme.form_element_checkbox_html_class}))
    max_choices = forms.IntegerField(
        label=_("Max choices"),
        required=False,
        widget=NumberInput(attrs={'class': theme.form_element_html_class}))

    def clean_initial(self):
        """Validating the initial value."""
        return validate_initial_for_multiple_choices(self, 'choices',
                                                     'initial')
Beispiel #10
0
class TextareaForm(forms.Form, BaseFormFieldPluginForm):
    """Form for ``TextareaPlugin``."""

    plugin_data_fields = [
        ("label", ""),
        ("name", ""),
        ("help_text", ""),
        ("initial", ""),
        ("required", False),
        ("max_length", ""),
        ("placeholder", ""),
    ]

    label = forms.CharField(
        label=_("Label"),
        required=True,
        widget=forms.widgets.TextInput(
            attrs={'class': theme.form_element_html_class}))
    name = forms.CharField(label=_("Name"),
                           required=True,
                           widget=forms.widgets.TextInput(
                               attrs={'class': theme.form_element_html_class}))
    help_text = forms.CharField(
        label=_("Help text"),
        required=False,
        widget=forms.widgets.Textarea(
            attrs={'class': theme.form_element_html_class}))
    initial = forms.CharField(
        label=_("Initial"),
        required=False,
        widget=forms.widgets.Textarea(
            attrs={'class': theme.form_element_html_class}))
    required = forms.BooleanField(
        label=_("Required"),
        required=False,
        widget=forms.widgets.CheckboxInput(
            attrs={'class': theme.form_element_checkbox_html_class}))
    max_length = forms.IntegerField(
        label=_("Max length"),
        required=False,
        widget=NumberInput(attrs={'class': theme.form_element_html_class}))
    placeholder = forms.CharField(
        label=_("Placeholder"),
        required=False,
        widget=forms.widgets.TextInput(
            attrs={'class': theme.form_element_html_class}))
Beispiel #11
0
class HiddenInputForm(forms.Form, BaseFormFieldPluginForm):
    """Form for ``HiddenInputPlugin``."""

    plugin_data_fields = [
        ("label", ""),
        ("name", ""),
        ("initial", ""),
        ("max_length", "255"),
        ("required", False)
    ]

    label = forms.CharField(
        label=_("Label"),
        required=True,
        widget=forms.widgets.TextInput(
            attrs={'class': theme.form_element_html_class}
        )
    )
    name = forms.CharField(
        label=_("Name"),
        required=True,
        widget=forms.widgets.TextInput(
            attrs={'class': theme.form_element_html_class}
        )
    )
    initial = forms.CharField(
        label=_("Initial"),
        required=False,
        widget=forms.widgets.TextInput(
            attrs={'class': theme.form_element_html_class}
        )
    )
    max_length = forms.IntegerField(
        label=_("Max length"),
        required=True,
        widget=NumberInput(attrs={'class': theme.form_element_html_class}),
        initial=DEFAULT_MAX_LENGTH
    )
    required = forms.BooleanField(
        label=_("Required"),
        required=False,
        widget=forms.widgets.CheckboxInput(
            attrs={'class': theme.form_element_checkbox_html_class}
        )
    )
Beispiel #12
0
    def get_form_field_instances(self,
                                 request=None,
                                 form_entry=None,
                                 form_element_entries=None,
                                 **kwargs):
        """Get form field instances."""
        widget_attrs = {
            'class': theme.form_element_html_class,
            'type': 'number',
            'placeholder': self.data.placeholder,
        }
        field_kwargs = {
            'label': self.data.label,
            'help_text': self.data.help_text,
            'required': self.data.required,
        }

        if self.data.initial is not None:
            data_initial = decimal.Decimal(str(self.data.initial))
            field_kwargs.update({'initial': data_initial})

        if self.data.max_value is not None:
            data_max_value = decimal.Decimal(str(self.data.max_value))
            field_kwargs['max_value'] = data_max_value
            widget_attrs['max'] = data_max_value

        if self.data.min_value is not None:
            data_min_value = decimal.Decimal(str(self.data.min_value))
            field_kwargs['min_value'] = data_min_value
            widget_attrs['min'] = data_min_value

        if self.data.max_digits is not None:
            data_max_digits = int(self.data.max_digits)
            field_kwargs['max_digits'] = data_max_digits

        if self.data.decimal_places is not None:
            data_decimal_places = int(self.data.decimal_places)
            field_kwargs['decimal_places'] = data_decimal_places

        field_kwargs['widget'] = NumberInput(attrs=widget_attrs)

        return [(self.data.name, DecimalField, field_kwargs)]
Beispiel #13
0
class InputForm(forms.Form, BaseFormFieldPluginForm):
    """Form for ``InputPlugin``."""

    plugin_data_fields = [
        ("label", ""),
        ("name", ""),
        ("help_text", ""),
        ("initial", ""),
        ("max_length", str(DEFAULT_MAX_LENGTH)),
        ("required", False),
        ("placeholder", ""),

        # Additional elements
        ("autocomplete_value", "off"),  # Possible values are: on, off
        ("autofocus_value", False),  # If set to True, value should be
                                     # "autofocus"
        ("disabled_value", False),  # If set to True, value should
                                    # be "disabled"
        # ("formnovalidate_value", ""),  # If set to True, value should be
        #                                # "formnovalidate"
        ("list_value", ""),
        ("max_value", ""),
        ("min_value", ""),
        ("multiple_value", False),  # If set to True, value should
                                    # be "multiple"
        ("pattern_value", ""),
        ("readonly_value", False),  # If set to True, value should
                                    # be "readonly"
        ("step_value", ""),
        ("type_value", "text"),
    ]

    label = forms.CharField(
        label=_("Label"),
        required=True,
        widget=forms.widgets.TextInput(
            attrs={'class': theme.form_element_html_class}
        )
    )
    name = forms.CharField(
        label=_("Name"),
        required=True,
        widget=forms.widgets.TextInput(
            attrs={'class': theme.form_element_html_class}
        )
    )
    help_text = forms.CharField(
        label=_("Help text"),
        required=False,
        widget=forms.widgets.Textarea(
            attrs={'class': theme.form_element_html_class}
        )
    )
    initial = forms.CharField(
        label=_("Initial"),
        required=False,
        widget=forms.widgets.TextInput(
            attrs={'class': theme.form_element_html_class}
        )
    )
    max_length = forms.IntegerField(
        label=_("Max length"),
        required=True,
        widget=NumberInput(attrs={'class': theme.form_element_html_class,
                                  'min': str(DEFAULT_MIN_LENGTH)}),
        initial=DEFAULT_MAX_LENGTH,
        validators=[MinValueValidator(DEFAULT_MIN_LENGTH)]
    )
    required = forms.BooleanField(
        label=_("Required"),
        required=False,
        widget=forms.widgets.CheckboxInput(
            attrs={'class': theme.form_element_checkbox_html_class}
        )
    )
    placeholder = forms.CharField(
        label=_("Placeholder"),
        required=False,
        widget=forms.widgets.TextInput(
            attrs={'class': theme.form_element_html_class}
        )
    )

    # Additional elements
    autocomplete_value = forms.BooleanField(
        label=_("Auto-complete (HTML5 autocomplete)"),
        required=False,
        widget=forms.widgets.CheckboxInput(
            attrs={'class': theme.form_element_checkbox_html_class}
        )
    )
    autofocus_value = forms.BooleanField(
        label=_("Auto-focus (HTML5 autofocus)"),
        required=False,
        widget=forms.widgets.CheckboxInput(
            attrs={'class': theme.form_element_checkbox_html_class}
        )
    )
    disabled_value = forms.BooleanField(
        label=_("Disabled"),
        required=False,
        widget=forms.widgets.CheckboxInput(
            attrs={'class': theme.form_element_checkbox_html_class}
        )
    )
    # formnovalidate_value = forms.BooleanField(
    #     label=_("Skip validation (HTML5 formnovalidate)"),
    #     required=False,
    #     widget=forms.widgets.CheckboxInput(
    #         attrs={'class': theme.form_element_html_class}
    #     )
    # )
    list_value = forms.CharField(
        label=_("List (HTML5 list)"),
        required=False,
        widget=forms.widgets.TextInput(
            attrs={'class': theme.form_element_html_class}
        )
    )
    max_value = forms.CharField(
        label=_("Max (HTML5 max)"),
        required=False,
        widget=forms.widgets.TextInput(
            attrs={'class': theme.form_element_html_class}
        )
    )
    min_value = forms.CharField(
        label=_("Min (HTML5 min)"),
        required=False,
        widget=forms.widgets.TextInput(
            attrs={'class': theme.form_element_html_class}
        )
    )
    multiple_value = forms.BooleanField(
        label=_("Multiple (HTML5 multiple)"),
        required=False,
        widget=forms.widgets.CheckboxInput(
            attrs={'class': theme.form_element_checkbox_html_class}
        )
    )
    pattern_value = forms.CharField(
        label=_("Pattern (HTML5 pattern)"),
        required=False,
        widget=forms.widgets.TextInput(
            attrs={'class': theme.form_element_html_class}
        )
    )
    readonly_value = forms.BooleanField(
        label=_("Read-only (HTML readonly)"),
        required=False,
        widget=forms.widgets.CheckboxInput(
            attrs={'class': theme.form_element_checkbox_html_class}
        )
    )
    step_value = forms.IntegerField(
        label=_("Step (HTML5 step)"),
        required=False,
        widget=NumberInput(attrs={'class': theme.form_element_html_class})
    )
    type_value = forms.ChoiceField(
        label=_("Type (HTML type)"),
        required=False,
        choices=FORM_FIELD_TYPE_CHOICES,
        widget=forms.widgets.Select(
            attrs={'class': theme.form_element_html_class}
        )
    )

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

        max_length = self.cleaned_data.get('max_length', DEFAULT_MAX_LENGTH)

        if self.cleaned_data['initial']:
            len_initial = len(self.cleaned_data['initial'])
            if len_initial > max_length:
                self.add_error(
                    'initial',
                    _("Ensure this value has at most {0} characters "
                      "(it has {1}).".format(max_length, len_initial))
                )
Beispiel #14
0
class InputForm(forms.Form, BaseFormFieldPluginForm):
    """Form for ``InputPlugin``."""

    plugin_data_fields = [
        ("label", ""),
        ("name", ""),
        ("help_text", ""),
        ("initial", ""),
        ("max_length", "255"),
        ("required", False),
        ("placeholder", ""),

        # Additional elements
        ("autocomplete_value", "off"),  # Possible values are: on, off
        ("autofocus_value", False),  # If set to True, value should be
        # "autofocus"
        ("disabled_value", False),  # If set to True, value should
        # be "disabled"
        # ("formnovalidate_value", ""),  # If set to True, value should be
        #                                # "formnovalidate"
        ("list_value", ""),
        ("max_value", ""),
        ("min_value", ""),
        ("multiple_value", False),  # If set to True, value should
        # be "multiple"
        ("pattern_value", ""),
        ("readonly_value", False),  # If set to True, value should
        # be "readonly"
        ("step_value", ""),
        ("type_value", "text"),
    ]

    label = forms.CharField(
        label=_("Label"),
        required=True,
        widget=forms.widgets.TextInput(
            attrs={'class': theme.form_element_html_class}))
    name = forms.CharField(label=_("Name"),
                           required=True,
                           widget=forms.widgets.TextInput(
                               attrs={'class': theme.form_element_html_class}))
    help_text = forms.CharField(
        label=_("Help text"),
        required=False,
        widget=forms.widgets.Textarea(
            attrs={'class': theme.form_element_html_class}))
    initial = forms.CharField(
        label=_("Initial"),
        required=False,
        widget=forms.widgets.TextInput(
            attrs={'class': theme.form_element_html_class}))
    max_length = forms.IntegerField(
        label=_("Max length"),
        required=True,
        widget=NumberInput(attrs={'class': theme.form_element_html_class}),
        initial=DEFAULT_MAX_LENGTH)
    required = forms.BooleanField(
        label=_("Required"),
        required=False,
        widget=forms.widgets.CheckboxInput(
            attrs={'class': theme.form_element_checkbox_html_class}))
    placeholder = forms.CharField(
        label=_("Placeholder"),
        required=False,
        widget=forms.widgets.TextInput(
            attrs={'class': theme.form_element_html_class}))

    # Additional elements
    autocomplete_value = forms.BooleanField(
        label=_("Auto-complete (HTML5 autocomplete)"),
        required=False,
        widget=forms.widgets.CheckboxInput(
            attrs={'class': theme.form_element_checkbox_html_class}))
    autofocus_value = forms.BooleanField(
        label=_("Auto-focus (HTML5 autofocus)"),
        required=False,
        widget=forms.widgets.CheckboxInput(
            attrs={'class': theme.form_element_checkbox_html_class}))
    disabled_value = forms.BooleanField(
        label=_("Disabled"),
        required=False,
        widget=forms.widgets.CheckboxInput(
            attrs={'class': theme.form_element_checkbox_html_class}))
    # formnovalidate_value = forms.BooleanField(
    #     label=_("Skip validation (HTML5 formnovalidate)"),
    #     required=False,
    #     widget=forms.widgets.CheckboxInput(
    #         attrs={'class': theme.form_element_html_class}
    #     )
    # )
    list_value = forms.CharField(
        label=_("List (HTML5 list)"),
        required=False,
        widget=forms.widgets.TextInput(
            attrs={'class': theme.form_element_html_class}))
    max_value = forms.CharField(
        label=_("Max (HTML5 max)"),
        required=False,
        widget=forms.widgets.TextInput(
            attrs={'class': theme.form_element_html_class}))
    min_value = forms.CharField(
        label=_("Min (HTML5 min)"),
        required=False,
        widget=forms.widgets.TextInput(
            attrs={'class': theme.form_element_html_class}))
    multiple_value = forms.BooleanField(
        label=_("Multiple (HTML5 multiple)"),
        required=False,
        widget=forms.widgets.CheckboxInput(
            attrs={'class': theme.form_element_checkbox_html_class}))
    pattern_value = forms.CharField(
        label=_("Pattern (HTML5 pattern)"),
        required=False,
        widget=forms.widgets.TextInput(
            attrs={'class': theme.form_element_html_class}))
    readonly_value = forms.BooleanField(
        label=_("Read-only (HTML readonly)"),
        required=False,
        widget=forms.widgets.CheckboxInput(
            attrs={'class': theme.form_element_checkbox_html_class}))
    step_value = forms.IntegerField(
        label=_("Step (HTML5 step)"),
        required=False,
        widget=NumberInput(attrs={'class': theme.form_element_html_class}))
    type_value = forms.ChoiceField(
        label=_("Type (HTML type)"),
        required=False,
        choices=FORM_FIELD_TYPE_CHOICES,
        widget=forms.widgets.Select(
            attrs={'class': theme.form_element_html_class}))
Beispiel #15
0
class SliderInputForm(forms.Form, BaseFormFieldPluginForm):
    """Form for ``SliderInputPlugin``."""

    plugin_data_fields = [
        ("label", ""),
        ("name", ""),
        ("initial", INITIAL),
        ("min_value", INITIAL_MIN_VALUE),
        ("max_value", INITIAL_MAX_VALUE),
        ("step", STEP),
        ("tooltip", SLIDER_DEFAULT_TOOLTIP),
        ("handle", SLIDER_DEFAULT_HANDLE),
        # ("disable_slider_background", False),
        ("show_endpoints_as", SLIDER_DEFAULT_SHOW_ENDPOINTS_AS),
        ("label_start", ""),
        ("label_end", ""),
        ("custom_ticks", ""),
        ("help_text", ""),
        ("required", False)
    ]

    label = forms.CharField(
        label=_("Label"),
        required=True,
        widget=forms.widgets.TextInput(
            attrs={'class': theme.form_element_html_class}))
    name = forms.CharField(label=_("Name"),
                           required=True,
                           widget=forms.widgets.TextInput(
                               attrs={'class': theme.form_element_html_class}))
    initial = forms.IntegerField(
        label=_("Initial"),
        required=False,
        widget=NumberInput(attrs={'class': theme.form_element_html_class}),
        min_value=MIN_VALUE,
        max_value=MAX_VALUE,
        initial=INITIAL)
    min_value = forms.IntegerField(
        label=_("Min value"),
        required=True,
        initial=INITIAL_MIN_VALUE,
        widget=NumberInput(attrs={'class': theme.form_element_html_class}),
        min_value=MIN_VALUE,
        max_value=MAX_VALUE)
    max_value = forms.IntegerField(
        label=_("Max value"),
        required=True,
        initial=INITIAL_MAX_VALUE,
        widget=NumberInput(attrs={'class': theme.form_element_html_class}),
        min_value=MIN_VALUE,
        max_value=MAX_VALUE)
    step = forms.IntegerField(
        label=_("Step"),
        required=True,
        help_text=_("Step size"),
        widget=NumberInput(attrs={'class': theme.form_element_html_class}),
        min_value=MIN_VALUE,
        max_value=MAX_VALUE)
    tooltip = forms.ChoiceField(
        label=_("Tooltip"),
        choices=SLIDER_TOOLTIP_CHOICES,
        required=False,
        widget=forms.widgets.Select(
            attrs={'class': theme.form_element_html_class}))
    handle = forms.ChoiceField(
        label=_("Handle"),
        choices=SLIDER_HANDLE_CHOICES,
        required=False,
        widget=forms.widgets.Select(
            attrs={'class': theme.form_element_html_class}))
    # disable_slider_background = forms.BooleanField(
    #     label=_("Disable slider background"),
    #     required=False,
    #     widget=forms.widgets.CheckboxInput(
    #         attrs={'class': theme.form_element_checkbox_html_class}
    #     )
    # )
    show_endpoints_as = forms.ChoiceField(
        label=_("Show endpoints as"),
        choices=SLIDER_SHOW_ENDPOINTS_AS_CHOICES,
        required=False,
        widget=forms.widgets.Select(
            attrs={'class': theme.form_element_html_class}))
    label_start = forms.CharField(
        label=_("Start label"),
        help_text=_("Start endpoint label"),
        required=False,
        widget=forms.widgets.TextInput(
            attrs={'class': theme.form_element_html_class}))
    label_end = forms.CharField(
        label=_("End label"),
        help_text=_("End endpoint label"),
        required=False,
        widget=forms.widgets.TextInput(
            attrs={'class': theme.form_element_html_class}))
    custom_ticks = forms.CharField(
        label=_("Custom ticks"),
        required=False,
        help_text=_("Enter single values/pairs per line. Example:<code><br/>"
                    "&nbsp;&nbsp;&nbsp;&nbsp;1<br/>"
                    "&nbsp;&nbsp;&nbsp;&nbsp;2<br/>"
                    "&nbsp;&nbsp;&nbsp;&nbsp;3, Alpha<br/>"
                    "&nbsp;&nbsp;&nbsp;&nbsp;4, Beta<br/>"
                    "</code><br/>"
                    "It finally transforms into the following HTML "
                    "code:<code><br/>"
                    '&nbsp;&nbsp;&nbsp;&nbsp;'
                    'data-slider-ticks="[1, 2, 3, 4]"<br/>'
                    '&nbsp;&nbsp;&nbsp;&nbsp;'
                    "data-slider-ticks-labels='"
                    '["1", "2", "Alpha", "Beta"]'
                    "'</code>"),
        widget=forms.widgets.Textarea(
            attrs={'class': theme.form_element_html_class}))
    help_text = forms.CharField(
        label=_("Help text"),
        required=False,
        widget=forms.widgets.TextInput(
            attrs={'class': theme.form_element_html_class}))
    required = forms.BooleanField(
        label=_("Required"),
        required=False,
        widget=forms.widgets.CheckboxInput(
            attrs={'class': theme.form_element_checkbox_html_class}))

    def clean(self):
        """Validating the values."""
        super(SliderInputForm, self).clean()

        max_value = self.cleaned_data['max_value']
        min_value = self.cleaned_data['min_value']
        initial = self.cleaned_data['initial']
        step = self.cleaned_data['step']
        show_endpoints_as = self.cleaned_data['show_endpoints_as']
        handle = self.cleaned_data['handle']
        custom_ticks = self.cleaned_data['custom_ticks']

        if max_value < min_value:
            self.add_error('max_value',
                           _("`max_value` should be > than `min_value`."))

        if step > max_value - min_value:
            self.add_error(
                'step',
                _("`step` should be > than `max_value` - `min_value`."))

        if max_value < initial:
            self.add_error('initial',
                           _("`max_value` should be >= than `initial`."))

        if min_value > initial:
            self.add_error('min_value',
                           _("`initial` should be >= than `min_value`."))

        label_handles = (SLIDER_HANDLE_TRIANGLE, SLIDER_HANDLE_CUSTOM)
        tick_endpoints = (SLIDER_SHOW_ENDPOINTS_AS_LABELED_TICKS,
                          SLIDER_SHOW_ENDPOINTS_AS_TICKS)
        if handle in label_handles and show_endpoints_as in tick_endpoints:
            self.add_error(
                'handle',
                _("You are not allowed to use Triangle or Custom handles "
                  "with ticks enabled."))

        if custom_ticks:
            ticks = get_select_field_choices(custom_ticks,
                                             key_type=int,
                                             value_type=str,
                                             fail_silently=False)
            if ticks is None:
                self.add_error(
                    'custom_ticks',
                    _("Invalid format. First value should be an integer, "
                      "second value should be a string."))
Beispiel #16
0
class FloatInputForm(forms.Form, BaseFormFieldPluginForm):
    """Form for ``FloatInputPlugin``."""

    plugin_data_fields = [
        ("label", ""),
        ("name", ""),
        ("help_text", ""),
        ("initial", ""),
        ("min_value", None),
        ("max_value", None),
        ("required", False),
        ("placeholder", ""),
    ]

    label = forms.CharField(
        label=_("Label"),
        required=True,
        widget=forms.widgets.TextInput(
            attrs={'class': theme.form_element_html_class}))
    name = forms.CharField(label=_("Name"),
                           required=True,
                           widget=forms.widgets.TextInput(
                               attrs={'class': theme.form_element_html_class}))
    help_text = forms.CharField(
        label=_("Help text"),
        required=False,
        widget=forms.widgets.Textarea(
            attrs={'class': theme.form_element_html_class}))
    initial = forms.FloatField(
        label=_("Initial"),
        required=False,
        widget=NumberInput(attrs={'class': theme.form_element_html_class}))
    min_value = forms.FloatField(
        label=_("Min value"),
        required=False,
        widget=NumberInput(attrs={'class': theme.form_element_html_class}))
    max_value = forms.FloatField(
        label=_("Max value"),
        required=False,
        widget=NumberInput(attrs={'class': theme.form_element_html_class}))
    required = forms.BooleanField(
        label=_("Required"),
        required=False,
        widget=forms.widgets.CheckboxInput(
            attrs={'class': theme.form_element_checkbox_html_class}))
    placeholder = forms.CharField(
        label=_("Placeholder"),
        required=False,
        widget=forms.widgets.TextInput(
            attrs={'class': theme.form_element_html_class}))

    def clean(self):
        """Validating the values."""
        super(FloatInputForm, self).clean()

        max_value = self.cleaned_data['max_value']
        min_value = self.cleaned_data['min_value']
        initial = self.cleaned_data['initial']

        if (max_value is not None and min_value is not None
                and max_value < min_value):
            self.add_error('max_value',
                           _("`max_value` should be > than `min_value`."))

        if max_value is not None and initial and max_value < initial:
            self.add_error('initial',
                           _("`max_value` should be >= than `initial`."))

        if min_value is not None and initial and min_value > initial:
            self.add_error('min_value',
                           _("`initial` should be >= than `min_value`."))
Beispiel #17
0
class IPAddressInputForm(forms.Form, BaseFormFieldPluginForm):
    """Form for ``IPAddressInputPlugin``."""

    plugin_data_fields = [
        ("label", ""),
        ("name", ""),
        ("help_text", ""),
        ("initial", ""),
        ("protocol", ""),
        ("unpack_ipv4", False),
        ("max_length", str(DEFAULT_MAX_LENGTH)),
        ("required", False),
        ("placeholder", ""),
    ]

    label = forms.CharField(
        label=_("Label"),
        required=True,
        widget=forms.widgets.TextInput(
            attrs={'class': theme.form_element_html_class}))
    name = forms.CharField(label=_("Name"),
                           required=True,
                           widget=forms.widgets.TextInput(
                               attrs={'class': theme.form_element_html_class}))
    help_text = forms.CharField(
        label=_("Help text"),
        required=False,
        widget=forms.widgets.Textarea(
            attrs={'class': theme.form_element_html_class}))
    initial = forms.CharField(
        label=_("Initial"),
        required=False,
        widget=forms.widgets.TextInput(
            attrs={'class': theme.form_element_html_class}))
    protocol = forms.ChoiceField(
        label=_("Protocol"),
        choices=[(pr, pr) for pr in ip_address_validator_map.keys()],
        required=True,
        widget=forms.widgets.Select(
            attrs={'class': theme.form_element_html_class}))
    unpack_ipv4 = forms.BooleanField(
        label=_("Unpack IPV4"),
        required=False,
        widget=forms.widgets.CheckboxInput(
            attrs={'class': theme.form_element_checkbox_html_class}))
    max_length = forms.IntegerField(
        label=_("Max length"),
        required=True,
        widget=NumberInput(attrs={
            'class': theme.form_element_html_class,
            'min': str(DEFAULT_MIN_LENGTH)
        }),
        initial=DEFAULT_MAX_LENGTH,
        validators=[MinValueValidator(DEFAULT_MIN_LENGTH)])
    required = forms.BooleanField(
        label=_("Required"),
        required=False,
        widget=forms.widgets.CheckboxInput(
            attrs={'class': theme.form_element_checkbox_html_class}))
    placeholder = forms.CharField(
        label=_("Placeholder"),
        required=False,
        widget=forms.widgets.TextInput(
            attrs={'class': theme.form_element_html_class}))

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

        max_length = self.cleaned_data.get('max_length', DEFAULT_MAX_LENGTH)

        if self.cleaned_data['initial']:
            len_initial = len(self.cleaned_data['initial'])
            if len_initial > max_length:
                self.add_error(
                    'initial',
                    _("Ensure this value has at most {0} characters "
                      "(it has {1}).".format(max_length, len_initial)))
Beispiel #18
0
class DecimalInputForm(forms.Form, BaseFormFieldPluginForm):
    """Form for ``DecimalInputPlugin``."""

    plugin_data_fields = [
        ("label", ""),
        ("name", ""),
        ("help_text", ""),
        ("initial", ""),
        ("max_digits", ""),
        ("decimal_places", ""),
        ("min_value", None),
        ("max_value", None),
        ("required", False),
        ("placeholder", ""),
    ]

    label = forms.CharField(
        label=_("Question text"),
        required=True,
        widget=forms.widgets.TextInput(
            attrs={'class': theme.form_element_html_class}))
    name = forms.CharField(label=_("Name"),
                           required=True,
                           widget=forms.widgets.TextInput(
                               attrs={'class': theme.form_element_html_class}))
    help_text = forms.CharField(
        label=_("Help text"),
        required=False,
        widget=forms.widgets.Textarea(
            attrs={'class': theme.form_element_html_class}))
    initial = forms.DecimalField(
        label=_("Initial"),
        required=False,
        widget=NumberInput(attrs={'class': theme.form_element_html_class}))
    max_digits = forms.IntegerField(
        label=_("Max digits"),
        required=False,
        widget=NumberInput(attrs={'class': theme.form_element_html_class}))
    decimal_places = forms.IntegerField(
        label=_("Decimal places"),
        required=False,
        widget=NumberInput(attrs={'class': theme.form_element_html_class}))
    min_value = forms.DecimalField(
        label=_("Min value"),
        required=False,
        widget=NumberInput(attrs={'class': theme.form_element_html_class}))
    max_value = forms.DecimalField(
        label=_("Max value"),
        required=False,
        widget=NumberInput(attrs={'class': theme.form_element_html_class}))
    required = forms.BooleanField(
        label=_("Required"),
        required=False,
        widget=forms.widgets.CheckboxInput(
            attrs={'class': theme.form_element_checkbox_html_class}))
    placeholder = forms.CharField(
        label=_("Placeholder"),
        required=False,
        widget=forms.widgets.TextInput(
            attrs={'class': theme.form_element_html_class}))

    def clean(self):
        """Validating the values."""
        super(DecimalInputForm, self).clean()

        max_value = self.cleaned_data['max_value']
        min_value = self.cleaned_data['min_value']
        decimal_places = self.cleaned_data['decimal_places']
        max_digits = self.cleaned_data['max_digits']
        initial = self.cleaned_data['initial']

        if (max_value is not None and min_value is not None
                and max_value < min_value):
            self.add_error('max_value',
                           _("`max_value` should be > than `min_value`."))

        if max_value is not None and initial and max_value < initial:
            self.add_error('initial',
                           _("`max_value` should be >= than `initial`."))

        if min_value is not None and initial and min_value > initial:
            self.add_error('min_value',
                           _("`initial` should be >= than `min_value`."))

        try:
            self.quantize(initial, decimal_places, max_digits)
        except decimal.InvalidOperation as err:
            self.add_error(
                'max_digits',
                _("Quantize result has too many digits for current context"))

    def quantize(self, value, decimal_places, max_digits):
        """Quantize the decimal value to the configured precision."""
        if decimal_places is None or value is None:
            return value

        context = decimal.getcontext().copy()
        if max_digits is not None:
            context.prec = max_digits
        return value.quantize(decimal.Decimal('.1')**decimal_places,
                              context=context)
Beispiel #19
0
class SelectMultipleWithMaxInputForm(forms.Form, BaseFormFieldPluginForm):
    """Form for ``SelectMultipleWithMaxInputPlugin``."""

    plugin_data_fields = [("label", ""), ("name", ""), ("choices", ""),
                          ("help_text", ""), ("initial", ""),
                          ("required", False), ("max_choices", "")]

    label = forms.CharField(
        label=_("Label"),
        required=True,
        widget=forms.widgets.TextInput(
            attrs={'class': theme.form_element_html_class}))
    name = forms.CharField(label=_("Name"),
                           required=True,
                           widget=forms.widgets.TextInput(
                               attrs={'class': theme.form_element_html_class}))
    choices = forms.CharField(
        label=_("Choices"),
        required=False,
        help_text=_("Enter single values/pairs per line. Example:<code><br/>"
                    "&nbsp;&nbsp;&nbsp;&nbsp;1<br/>"
                    "&nbsp;&nbsp;&nbsp;&nbsp;2<br/>"
                    "&nbsp;&nbsp;&nbsp;&nbsp;alpha, Alpha<br/>"
                    "&nbsp;&nbsp;&nbsp;&nbsp;beta, Beta<br/>"
                    "&nbsp;&nbsp;&nbsp;&nbsp;omega"
                    "</code><br/>"
                    "It finally transforms into the following HTML "
                    "code:<code><br/>"
                    '&nbsp;&nbsp;&nbsp;&nbsp;'
                    '&lt;select id="id_NAME_OF_THE_ELEMENT" '
                    'name="NAME_OF_THE_ELEMENT"&gt;<br/>'
                    '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
                    '&lt;option value="1"&gt;1&lt;/option&gt;<br/>'
                    '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
                    '&lt;option value="2"&gt;2&lt;/option&gt;<br/>'
                    '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
                    '&lt;option value="alpha"&gt;Alpha&lt;/option&gt;<br/>'
                    '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
                    '&lt;option value="beta"&gt;Beta&lt;/option&gt;<br/>'
                    '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
                    '&lt;option value="omega"&gt;omega&lt;/option&gt;<br/>'
                    '&nbsp;&nbsp;&nbsp;&nbsp;&lt;/select&gt;'
                    "</code>"),
        widget=forms.widgets.Textarea(
            attrs={'class': theme.form_element_html_class}))
    help_text = forms.CharField(
        label=_("Help text"),
        required=False,
        widget=forms.widgets.Textarea(
            attrs={'class': theme.form_element_html_class}))
    initial = forms.CharField(
        label=_("Initial"),
        required=False,
        widget=forms.widgets.TextInput(
            attrs={'class': theme.form_element_html_class}))
    required = forms.BooleanField(
        label=_("Required"),
        required=False,
        widget=forms.widgets.CheckboxInput(
            attrs={'class': theme.form_element_checkbox_html_class}))
    max_choices = forms.IntegerField(
        label=_("Max choices"),
        required=False,
        widget=NumberInput(attrs={'class': theme.form_element_html_class}))

    def clean_initial(self):
        """Validating the initial value."""
        return validate_initial_for_multiple_choices(self, 'choices',
                                                     'initial')
Beispiel #20
0
class TextInputForm(forms.Form, BaseFormFieldPluginForm):
    """Form for ``TextInputPlugin``."""

    plugin_data_fields = [
        ("label", ""),
        ("name", "name"),
        ("help_text", ""),
        ("initial", ""),
        ("max_length", str(DEFAULT_MAX_LENGTH)),
        ("required", False),
        ("placeholder", ""),
    ]

    label = forms.CharField(
        label=_("Question text"),
        required=True,
        widget=forms.widgets.TextInput(
            attrs={'class': theme.form_element_html_class}
        )
    )
    name = forms.CharField(
        label=_("Name"),
        required=True,
        widget=forms.widgets.HiddenInput(
            attrs={'class': theme.form_element_html_class}
        )
    )
    help_text = forms.CharField(
        label=_("Help text"),
        required=False,
        widget=forms.widgets.Textarea(
            attrs={'class': theme.form_element_html_class}
        ),
        help_text="This text will show up under the question and provide the \
                  survey taker with additional information."
    )
    initial = forms.CharField(
        label=_("Default answer"),
        required=False,
        widget=forms.widgets.TextInput(
            attrs={'class': theme.form_element_html_class}
        )
    )
    max_length = forms.IntegerField(
        label=_("Max length"),
        required=True,
        widget=NumberInput(attrs={'class': theme.form_element_html_class,
                                  'min': str(DEFAULT_MIN_LENGTH)}),
        initial=DEFAULT_MAX_LENGTH,
        validators=[MinValueValidator(DEFAULT_MIN_LENGTH)],
        help_text="The maximum number of characters that can be submitted for \
                  this question."
    )
    required = forms.BooleanField(
        label=_("Required"),
        required=False,
        widget=forms.widgets.CheckboxInput(
            attrs={'class': theme.form_element_checkbox_html_class}
        ),
        help_text="Is answering this question required to submit the survey?"
    )
    placeholder = forms.CharField(
        label=_("Placeholder"),
        required=False,
        widget=forms.widgets.HiddenInput(
            attrs={'class': theme.form_element_html_class}
        )
    )

    def clean(self):
        """Validation."""
        super(TextInputForm, self).clean()

        max_length = self.cleaned_data.get('max_length', DEFAULT_MAX_LENGTH)

        if self.cleaned_data['initial']:
            len_initial = len(self.cleaned_data['initial'])
            if len_initial > max_length:
                self.add_error(
                    'initial',
                    _("Ensure this value has at most {0} characters "
                      "(it has {1}).".format(max_length, len_initial))
                )
Beispiel #21
0
class TextareaForm(forms.Form, BaseFormFieldPluginForm):
    """Form for ``TextareaPlugin``."""

    plugin_data_fields = [
        ("label", ""),
        ("name", "name"),
        ("help_text", ""),
        ("initial", ""),
        ("required", False),
        ("max_length", ""),
        ("placeholder", "")
    ]

    label = forms.CharField(
        label=_("Question text"),
        required=True,
        widget=forms.widgets.TextInput(
            attrs={'class': theme.form_element_html_class}
        )
    )
    name = forms.CharField(
        label=_("Name"),
        required=True,
        widget=forms.widgets.HiddenInput(
            attrs={'class': theme.form_element_html_class}
        )
    )
    help_text = forms.CharField(
        label=_("Help text"),
        required=False,
        widget=forms.widgets.Textarea(
            attrs={'class': theme.form_element_html_class}
        ),
        help_text="This text will show up under the question and provide the \
                  survey taker with additional information."
    )
    initial = forms.CharField(
        label=_("Default answer"),
        required=False,
        widget=forms.widgets.Textarea(
            attrs={'class': theme.form_element_html_class}
        )
    )
    required = forms.BooleanField(
        label=_("Required"),
        required=False,
        widget=forms.widgets.CheckboxInput(
            attrs={'class': theme.form_element_checkbox_html_class}
        ),
        help_text="Is answering this question required to submit the survey?"
    )
    max_length = forms.IntegerField(
        label=_("Maximum length"),
        required=False,
        widget=NumberInput(
            attrs={'class': theme.form_element_html_class}
        ),
        help_text="The maximum number of characters that can be submitted for \
                  this question."
    )
    placeholder = forms.CharField(
        label=_("Placeholder"),
        required=False,
        widget=forms.widgets.HiddenInput(
            attrs={'class': theme.form_element_html_class}
        )
    )
Beispiel #22
0
class RangeSelectInputForm(forms.Form, BaseFormFieldPluginForm):
    """Form for ``RangeSelectInputPlugin``."""

    plugin_data_fields = [
        ("label", ""),
        ("name", ""),
        ("min_value", INITIAL_MIN_VALUE),
        ("max_value", INITIAL_MAX_VALUE),
        ("step", STEP),
        ("help_text", ""),
        ("initial", INITIAL),
        ("required", False)
    ]

    label = forms.CharField(
        label=_("Label"),
        required=True,
        widget=forms.widgets.TextInput(
            attrs={'class': theme.form_element_html_class}
        )
    )
    name = forms.CharField(
        label=_("Name"),
        required=True,
        widget=forms.widgets.TextInput(
            attrs={'class': theme.form_element_html_class}
        )
    )
    min_value = forms.IntegerField(
        label=_("Min value"),
        required=True,
        initial=INITIAL_MIN_VALUE,
        widget=NumberInput(attrs={'class': theme.form_element_html_class}),
        min_value=MIN_VALUE,
        max_value=MAX_VALUE
    )
    max_value = forms.IntegerField(
        label=_("Max value"),
        required=True,
        initial=INITIAL_MAX_VALUE,
        widget=NumberInput(attrs={'class': theme.form_element_html_class}),
        min_value=MIN_VALUE,
        max_value=MAX_VALUE
    )
    step = forms.IntegerField(
        label=_("Step"),
        required=True,
        help_text=_("Step size"),
        widget=NumberInput(attrs={'class': theme.form_element_html_class}),
        min_value=MIN_VALUE,
        max_value=MAX_VALUE
    )
    help_text = forms.CharField(
        label=_("Help text"),
        required=False,
        widget=forms.widgets.TextInput(
            attrs={'class': theme.form_element_html_class}
        )
    )
    initial = forms.IntegerField(
        label=_("Initial"),
        required=False,
        widget=NumberInput(attrs={'class': theme.form_element_html_class}),
        min_value=MIN_VALUE,
        max_value=MAX_VALUE,
        initial=INITIAL
    )
    required = forms.BooleanField(
        label=_("Required"),
        required=False,
        widget=forms.widgets.CheckboxInput(
            attrs={'class': theme.form_element_checkbox_html_class}
        )
    )

    def clean(self):
        """Validating the values."""
        super(RangeSelectInputForm, self).clean()

        max_value = self.cleaned_data['max_value']
        min_value = self.cleaned_data['min_value']
        initial = self.cleaned_data['initial']
        step = self.cleaned_data['step']

        if max_value < min_value:
            self.add_error(
                'max_value',
                _("`max_value` should be > than `min_value`.")
            )

        if step > max_value - min_value:
            self.add_error(
                'step',
                _("`step` should be > than `max_value` - `min_value`.")
            )

        if max_value < initial:
            self.add_error(
                'initial',
                _("`max_value` should be >= than `initial`.")
            )

        if min_value > initial:
            self.add_error(
                'min_value',
                _("`initial` should be >= than `min_value`.")
            )
Beispiel #23
0
class RegexInputForm(forms.Form, BaseFormFieldPluginForm):
    """Form for ``RegexInputPlugin``."""

    plugin_data_fields = [
        ("label", ""),
        ("name", ""),
        ("help_text", ""),
        ("initial", ""),
        ("regex", ""),
        ("max_length", "255"),
        ("required", False),
        ("placeholder", ""),
    ]

    label = forms.CharField(
        label=_("Label"),
        required=True,
        widget=forms.widgets.TextInput(
            attrs={'class': theme.form_element_html_class}))
    name = forms.CharField(label=_("Name"),
                           required=True,
                           widget=forms.widgets.TextInput(
                               attrs={'class': theme.form_element_html_class}))
    help_text = forms.CharField(
        label=_("Help text"),
        required=False,
        widget=forms.widgets.Textarea(
            attrs={'class': theme.form_element_html_class}))
    regex = forms.RegexField(
        label=_("Regex"),
        required=True,
        widget=forms.widgets.TextInput(
            attrs={'class': theme.form_element_html_class}),
        regex="",
        help_text=_("Enter a valid regular expression. A couple of common "
                    "examples are listed below.<br/>"
                    "- Allow a single digit from 1 to 9 (example value 6): "
                    "<code>^[1-9]$</code><br/>"
                    "- Allow any combination of characters from a to z, "
                    "including capitals (example value abcXYZ):"
                    "<code>^([a-zA-Z])+$</code><br/>"
                    "- Allow a hex value (example value #a5c125:"
                    "<code>^#?([a-f0-9]{6}|[a-f0-9]{3})$</code><br/>"))
    initial = forms.CharField(
        label=_("Initial"),
        required=False,
        widget=forms.widgets.TextInput(
            attrs={'class': theme.form_element_html_class}))
    max_length = forms.IntegerField(
        label=_("Max length"),
        required=True,
        widget=NumberInput(attrs={'class': theme.form_element_html_class}),
        initial=DEFAULT_MAX_LENGTH)
    required = forms.BooleanField(
        label=_("Required"),
        required=False,
        widget=forms.widgets.CheckboxInput(
            attrs={'class': theme.form_element_checkbox_html_class}))
    placeholder = forms.CharField(
        label=_("Placeholder"),
        required=False,
        widget=forms.widgets.TextInput(
            attrs={'class': theme.form_element_html_class}))
Beispiel #24
0
class RegexInputForm(forms.Form, BaseFormFieldPluginForm):
    """Form for ``RegexInputPlugin``."""

    plugin_data_fields = [
        ("label", ""),
        ("name", ""),
        ("help_text", ""),
        ("initial", ""),
        ("regex", ""),
        ("max_length", str(DEFAULT_MAX_LENGTH)),
        ("required", False),
        ("placeholder", ""),
    ]

    label = forms.CharField(
        label=_("Label"),
        required=True,
        widget=forms.widgets.TextInput(
            attrs={'class': theme.form_element_html_class}))
    name = forms.CharField(label=_("Name"),
                           required=True,
                           widget=forms.widgets.TextInput(
                               attrs={'class': theme.form_element_html_class}))
    help_text = forms.CharField(
        label=_("Help text"),
        required=False,
        widget=forms.widgets.Textarea(
            attrs={'class': theme.form_element_html_class}))
    regex = forms.RegexField(
        label=_("Regex"),
        required=True,
        widget=forms.widgets.TextInput(
            attrs={'class': theme.form_element_html_class}),
        regex="",
        help_text=_("Enter a valid regular expression. A couple of common "
                    "examples are listed below.<br/>"
                    "- Allow a single digit from 1 to 9 (example value 6): "
                    "<code>^[1-9]$</code><br/>"
                    "- Allow any combination of characters from a to z, "
                    "including capitals (example value abcXYZ):"
                    "<code>^([a-zA-Z])+$</code><br/>"
                    "- Allow a hex value (example value #a5c125:"
                    "<code>^#?([a-f0-9]{6}|[a-f0-9]{3})$</code><br/>"))
    initial = forms.CharField(
        label=_("Initial"),
        required=False,
        widget=forms.widgets.TextInput(
            attrs={'class': theme.form_element_html_class}))
    max_length = forms.IntegerField(
        label=_("Max length"),
        required=True,
        widget=NumberInput(attrs={
            'class': theme.form_element_html_class,
            'min': str(DEFAULT_MIN_LENGTH)
        }),
        initial=DEFAULT_MAX_LENGTH,
        validators=[MinValueValidator(DEFAULT_MIN_LENGTH)])
    required = forms.BooleanField(
        label=_("Required"),
        required=False,
        widget=forms.widgets.CheckboxInput(
            attrs={'class': theme.form_element_checkbox_html_class}))
    placeholder = forms.CharField(
        label=_("Placeholder"),
        required=False,
        widget=forms.widgets.TextInput(
            attrs={'class': theme.form_element_html_class}))

    def clean(self):
        """Validation."""
        super(RegexInputForm, self).clean()

        max_length = self.cleaned_data.get('max_length', DEFAULT_MAX_LENGTH)

        if self.cleaned_data['initial']:
            len_initial = len(self.cleaned_data['initial'])
            if len_initial > max_length:
                self.add_error(
                    'initial',
                    _("Ensure this value has at most {0} characters "
                      "(it has {1}).".format(max_length, len_initial)))
Beispiel #25
0
class FloatInputForm(forms.Form, BaseFormFieldPluginForm):
    """Form for ``FloatInputPlugin``."""

    plugin_data_fields = [("label", ""), ("name", "name"), ("help_text", ""),
                          ("initial", ""), ("min_value", None),
                          ("max_value", None), ("required", False)]

    label = forms.CharField(
        label=_("Question text"),
        required=True,
        widget=forms.widgets.TextInput(
            attrs={'class': theme.form_element_html_class}))
    name = forms.CharField(label=_("Name"),
                           required=True,
                           widget=forms.widgets.HiddenInput(
                               attrs={'class': theme.form_element_html_class}))
    help_text = forms.CharField(
        label=_("Help text"),
        required=False,
        widget=forms.widgets.Textarea(
            attrs={'class': theme.form_element_html_class}),
        help_text="This text will show up under the question and provide the \
                  survey taker with additional information.")
    initial = forms.FloatField(
        label=_("Default answer"),
        required=False,
        widget=NumberInput(attrs={'class': theme.form_element_html_class}))
    min_value = forms.FloatField(
        label=_("Minimum value"),
        required=False,
        widget=NumberInput(attrs={'class': theme.form_element_html_class}),
        help_text="The minimum value that can be entered for this question.")
    max_value = forms.FloatField(
        label=_("Maximum value"),
        required=False,
        widget=NumberInput(attrs={'class': theme.form_element_html_class}),
        help_text="The maximum value that can be entered for this question.")
    required = forms.BooleanField(
        label=_("Required"),
        required=False,
        widget=forms.widgets.CheckboxInput(
            attrs={'class': theme.form_element_checkbox_html_class}),
        help_text="Is answering this question required to submit the survey?")

    def clean(self):
        """Validating the values."""
        super(FloatInputForm, self).clean()

        max_value = self.cleaned_data['max_value']
        min_value = self.cleaned_data['min_value']
        initial = self.cleaned_data['initial']

        if (max_value is not None and min_value is not None
                and max_value < min_value):
            self.add_error('max_value',
                           _("`max_value` should be > than `min_value`."))

        if max_value is not None and initial and max_value < initial:
            self.add_error('initial',
                           _("`max_value` should be >= than `initial`."))

        if min_value is not None and initial and min_value > initial:
            self.add_error('min_value',
                           _("`initial` should be >= than `min_value`."))