Пример #1
0
    def setUp(self):
        """
        Set up: creates and saves models for form instance creation
        """
        form_class = Form(name='CustomForm')
        form_class.save()

        fieldset = FieldSet(form=form_class,
                            name='fieldset_1',
                            legend='This is a legend')
        fieldset.save()

        # A bunch of formulator fields, of all the FIELDS types
        for field_type in FIELDS:
            field_class = field_type[1]
            field_name = field_type[0]
            if field_name in REQUIRE_EXTRA_PARAMS:
                pass
            else:
                Field.objects.create(
                                     formset=fieldset,
                                     name=field_name,
                                     field=field_name,
                                     label=field_name,
                                     help_text="test help text",
                                     attrs={"placeholder":field_name}
                )

        # Class variable for the form class
        self.form_class = form_class.form_class_factory()

        # A generator providing the fields in the form
        self.field_getter = iter(self.form_class.base_fields.values())
Пример #2
0
    def setUp(self):
        """
        Set up: creates and saves models for form instance creation
        """
        form_class = Form(name='Form')
        form_class.save()

        fieldset = FieldSet(form=form_class,
                            name='fieldset_1',
                            legend='This is a legend')
        fieldset.save()

        # And a formulator field that will yield several form fields via the
        # repeat_min attribute
        self.field_name = 'foo'
        self.rep_min = 2
        self.rep_max = 5

        Field.objects.create(formset=fieldset,
                             name=self.field_name,
                             field='CharField',
                             repeat_min=self.rep_min,
                             repeat_max=self.rep_max,
        )

        self.form_class = form_class.form_class_factory()
Пример #3
0
    def test_clone_registration_form(self):
        # Composition of the form
        form_class = Form(name='RegistrationForm')
        form_class.save()

        # Composition of a Fieldset
        fieldset = FieldSet(form=form_class,
                            name='fieldset_1',
                            legend='This is a legend')
        fieldset.save()

        # Composition of the fields
        Field.objects.create(
            name="honeypot",
            field="CharField",
            required=False,
            widget="HiddenInput",
            formset=fieldset
        )
        Field.objects.create(
            name="firstname",
            field="CharField",
            label=_('Your first name?'),
            formset=fieldset
        )
        Field.objects.create(
            name="lastname",
            field="CharField",
            label=_('Your last name:'),
            formset=fieldset
        )
        Field.objects.create(
            name="username",
            field="CharField",
            attrs={"max_length": "30", "placeholder": "username here"},
            formset=fieldset
        )
        Field.objects.create(
            name="password",
            field="CharField",
            widget='PasswordInput',
            help_text=_('Make sure to use a secure password.'),
            formset=fieldset
        )
        Field.objects.create(
            name="password2",
            field="CharField",
            label=_('Retype password'),
            widget='PasswordInput',
            formset=fieldset
        )
        Field.objects.create(
            name="age",
            field="IntegerField",
            required=False,
            formset=fieldset
        )

        RegistrationFormClone = form_class.form_class_factory()
        
        # Assert that the HTML generated is the same
        self.assertEquals(RegistrationFormClone().as_p(), RegistrationForm().as_p(),)
Пример #4
0
from formulator.models import Form, FieldSet, Field
from django.utils.translation import ugettext_lazy as _

# FORM1
# =====
form_class = Form(name='sdv_form_en')
form_class.save()

# Composition of a Fieldset
fieldset = FieldSet(form=form_class,
                    name='fieldset1',
                    legend='This is a legend')
fieldset.save()

# Composition of the fields
Field.objects.create(   name="firstname",
                        field="CharField",
                        label=_('Your first name, SDV?'),
                        formset=fieldset
)
Field.objects.create(   name="lastname",
                        field="CharField",
                        label=_('Your last name, SDV?:'),
                        formset=fieldset
)
Field.objects.create(   name="username",
                        field="CharField",
                        attrs={"max_length":"30", "placeholder":"username here"},
                        formset=fieldset
)
Field.objects.create(   name="password",