File: forms.py

package info (click to toggle)
python-django-crispy-forms-foundation 1.0.2%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 852 kB
  • sloc: javascript: 6,437; python: 1,262; makefile: 195; sh: 17
file content (68 lines) | stat: -rw-r--r-- 1,766 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
"""
Used forms in tests
"""
from django import forms

from crispy_forms.helper import FormHelper
from crispy_forms_foundation.layout import Layout


class BasicInputForm(forms.Form):
    """
    Basic form with a single CharField field
    """
    simple = forms.CharField(label="Simple text",
                             widget=forms.TextInput(attrs={"required": ""}),
                             required=True)

    def save(self, commit=True):
        return


class BoolInputForm(forms.Form):
    """
    Basic form with a single BooleanField field
    """
    opt_in = forms.BooleanField(
            label="Opt in",
            widget=forms.CheckboxInput(attrs={"required":  ""}),
            required=True)

    def save(self, commit=True):
        return


class BasicInputFormLayoutIncluded(BasicInputForm):
    """
    Basic form with included layout
    """
    def __init__(self, *args, **kwargs):
        self.helper = kwargs.pop("helper", FormHelper())

        self.helper.form_action = "."

        self.helper.layout = Layout(
            "simple",
        )

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


class AdvancedForm(forms.Form):
    """
    Form with an advanced layout with some inputs
    """
    simple = forms.CharField(label="Simple text",
                             widget=forms.TextInput(attrs={"required": ""}),
                             required=True)

    opt_in = forms.BooleanField(
            label="Opt in",
            widget=forms.CheckboxInput(attrs={"required": ""}),
            required=True)

    longtext = forms.CharField(label="Address", required=False,
                               widget=forms.Textarea(attrs={"rows": 3}))

    def save(self, commit=True):
        return