コード例 #1
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.helper = FormHelper()
     self.helper.layout = Layout(
         Accordion(
             AccordionSection(
                 "Writing well for the web",
                 HTML.p(
                     "This is the content for Writing well for the web."),
                 summary="An introduction to clear and concise writing.",
             ),
             AccordionSection(
                 "Writing well for specialists",
                 HTML.
                 p("This is the content for Writing well for specialists."),
             ),
             AccordionSection(
                 "Know your audience",
                 HTML.p("This is the content for Know your audience."),
             ),
             AccordionSection(
                 "How people read",
                 HTML.p("This is the content for How people read."),
             ),
         ))
コード例 #2
0
 def valid_layout(self):
     file = self.cleaned_data["file"]
     self.helper.layout = Layout(
         HTML.h2("You uploaded..."),
         HTML.p("File: %s" % file),
         HTML('<a class="govuk-button" href="%s">Continue</a>' %
              reverse("components:name", kwargs={"name": "file-upload"})),
     )
コード例 #3
0
ファイル: textarea.py プロジェクト: wildfish/crispy-forms-gds
 def valid_layout(self):
     value = self.cleaned_data["description"]
     self.helper.layout = Layout(
         Hidden("description", value),
         HTML.h2("You answered..."),
         HTML.p(value),
         Button("continue", "Continue"),
     )
コード例 #4
0
ファイル: select.py プロジェクト: wildfish/crispy-forms-gds
 def valid_layout(self):
     value = self.cleaned_data["sort_by"]
     self.helper.layout = Layout(
         Hidden("sort_by", value),
         HTML.h2("You answered..."),
         HTML.table(None, [("Sort by:", self.get_choice("sort_by"))]),
         Button("continue", "Continue"),
     )
コード例 #5
0
 def valid_layout(self):
     self.fields["method"].widget = MultipleHiddenInput()
     self.helper.layout = Layout(
         "method",
         HTML.h2("You answered..."),
         HTML.table(None, [("Methods selected:", self.get_method())]),
         Button("continue", "Continue"),
     )
コード例 #6
0
ファイル: forms.py プロジェクト: wildfish/crispy-forms-gds
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.helper = FormHelper()
     self.helper.layout = Layout(
         Tabs(
             TabPanel("First Tab", HTML("<p>First panel</p>")),
             TabPanel("Second Tab", HTML("<p>Second panel</p>")),
         ))
コード例 #7
0
ファイル: date_input.py プロジェクト: ahernp/crispy-forms-gds
 def valid_layout(self):
     value = self.cleaned_data["date"]
     self.helper.layout = Layout(
         Hidden("date_0", value.day),
         Hidden("date_1", value.month),
         Hidden("date_2", value.year),
         HTML.h2("You answered..."),
         HTML.table(None, [("Date:", value.strftime("%e %B %Y"))]),
         Button("continue", "Continue"),
     )
コード例 #8
0
ファイル: text_input.py プロジェクト: ahernp/crispy-forms-gds
 def valid_layout(self):
     name = self.cleaned_data["name"]
     email = self.cleaned_data["email"]
     phone = self.cleaned_data["phone"]
     self.helper.layout = Layout(
         Hidden("name", name),
         Hidden("email", email),
         Hidden("phone", phone),
         HTML.h2("You answered..."),
         HTML.table(None, [("Name:", name), ("Email:", email),
                           ("Phone:", phone)]),
         Button("continue", "Continue"),
     )
コード例 #9
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.helper = FormHelper()
     self.helper.label_size = Size.SMALL
     self.helper.legend_size = Size.SMALL
     self.helper.layout = Layout(
         Div(
             Field.text("sid", field_width=Fluid.TWO_THIRDS),
             "goods_nomenclature",
             "additional_code",
             "order_number",
             "measure_type",
             "regulation",
             "geographical_area",
             "footnote",
             css_class="govuk-grid-row quarters",
         ),
         HTML(
             '<hr class="govuk-section-break govuk-section-break--s govuk-section-break--visible">',
         ),
         Div(
             Div(
                 Field.radios(
                     "start_date_modifier",
                     inline=True,
                 ),
                 "start_date",
                 css_class=
                 "govuk-grid-column-one-half form-group-margin-bottom-2",
             ),
             Div(
                 Field.radios(
                     "end_date_modifier",
                     inline=True,
                 ),
                 "end_date",
                 css_class=
                 "govuk-grid-column-one-half form-group-margin-bottom-2",
             ),
             css_class="govuk-grid-row govuk-!-margin-top-6",
         ),
         HTML(
             '<hr class="govuk-section-break govuk-section-break--s govuk-section-break--visible">',
         ),
         Button("submit",
                "Search and Filter",
                css_class="govuk-!-margin-top-6"),
         HTML(
             f'<a class="govuk-button govuk-button--secondary govuk-!-margin-top-6" href="{self.clear_url}"> Clear </a>',
         ),
     )
コード例 #10
0
ファイル: forms.py プロジェクト: wildfish/crispy-forms-gds
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.helper = FormHelper()
     self.helper.layout = Layout(
         Accordion(
             AccordionSection(
                 "First section",
                 HTML("<p>First section contents.</p>"),
                 summary="A summary of the first section",
             ),
             AccordionSection(
                 "Second section",
                 HTML("<p>Second section contents.</p>"),
             ),
         ))
コード例 #11
0
def test_parameters(headers, rows, caption, header_css, row_css):
    field = HTML.table(headers,
                       rows,
                       caption=caption,
                       header_css=header_css,
                       row_css=row_css)
    assert isinstance(field, HTML)
コード例 #12
0
def test_section_attributes():
    """Verify extra attributes can be added to an accordion section."""
    form = AccordionForm()
    form.helper.layout = Layout(
        Accordion(AccordionSection("Title", HTML("Contents"), key="value")))
    assert parse_form(form) == parse_contents(RESULT_DIR,
                                              "section_attributes.html")
コード例 #13
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.helper.layout = Layout(
         Fieldset(
             "public_identifier",
             self._load_details_from_template(
                 "Help with public identifiers",
                 "regulations/help_public_identifiers.jinja",
             ),
             Field(
                 "url",
                 css_class="govuk-input",
             ),
             "regulation_group",
             self._load_details_from_template(
                 "Help with regulation group",
                 "regulations/help_regulation_group.jinja",
             ),
             "information_text",
             "start_date",
             "end_date",
             "published_at",
             HTML.details(
                 "Help with Published date",
                 RegulationFormBase.PUBLISHED_AT_HELP_TEXT,
             ),
             "approved",
         ),
         Submit(
             "submit",
             "Save",
             data_module="govuk-button",
             data_prevent_double_click="true",
         ),
     )
コード例 #14
0
 def valid_layout(self):
     name = self.cleaned_data["name"]
     method = self.cleaned_data["method"]
     self.helper.layout = Layout(
         Hidden("name", name),
         Hidden("method", method),
         HTML.h2("You answered..."),
         HTML.table(
             None,
             [
                 ("Name changed:", self.get_choice("name")),
                 ("Contact method:", self.get_choice("method")),
             ],
         ),
         Button("continue", "Continue"),
     )
コード例 #15
0
 def _load_details_from_template(self, title, template_path):
     public_identifier_details_content = loader.render_to_string(
         template_path, )
     return HTML.details(
         title,
         SafeString(public_identifier_details_content),
     )
コード例 #16
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.helper = FormHelper()
     self.helper.layout = Layout(
         HTML.warning(
             "You can be fined up to £5,000 if you do not like this template pack."
         ))
コード例 #17
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.helper = FormHelper()
     self.helper.layout = Layout(
         HTML.inset(
             "It can take up to 8 weeks to register a lasting power of "
             "attorney if there are no mistakes in the application. "))
コード例 #18
0
def test_section_css_id():
    """Verify the accordion section id can be set."""
    form = AccordionForm()
    form.helper.layout = Layout(
        Accordion(AccordionSection("Title", HTML("Contents"),
                                   css_id="new_id")))
    assert parse_form(form) == parse_contents(RESULT_DIR,
                                              "section_css_id.html")
コード例 #19
0
def test_section_css_class():
    """Verify an extra CSS class can be added to an accordion section."""
    form = AccordionForm()
    form.helper.layout = Layout(
        Accordion(
            AccordionSection("Title",
                             HTML("Contents"),
                             css_class="extra-css-class")))
    assert parse_form(form) == parse_contents(RESULT_DIR,
                                              "section_css_class.html")
コード例 #20
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.helper = FormHelper()
     self.helper.layout = Layout(
         Div(Button.primary("add", "Add contact")),
         Div(Button.secondary("find", "Find address")),
         Div(Button.secondary("win", "Win lottery", disabled=True)),
         Div(Button.warning("delete", "Delete account")),
         Div(HTML(button_link(reverse("home"), "Go Home"))),
     )
コード例 #21
0
ファイル: details.py プロジェクト: wildfish/crispy-forms-gds
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.helper = FormHelper()
     self.helper.layout = Layout(
         HTML.details(
             "Help with nationality",
             "We need to know your nationality so we can work out which "
             "elections you’re entitled to vote in. If you cannot provide "
             "your nationality, you’ll have to send copies of identity "
             "documents through the post.",
         ))
コード例 #22
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        headings = ["Name of user", "status"]
        statuses = [
            [
                "Rachel Silver",
                mark_safe(HTML.tag("Pending", Colour.BLUE).html)
            ],
            [
                "Jesse Smith",
                mark_safe(HTML.tag("Inactive", Colour.PURPLE).html)
            ],
            [
                "Joshua Wessel ",
                mark_safe(HTML.tag("Active", Colour.GREEN).html)
            ],
            ["Tim Harvey",
             mark_safe(HTML.tag("Blocked", Colour.RED).html)],
            [
                "Rachael Pepper",
                mark_safe(HTML.tag("Disabled", Colour.GREY).html)
            ],
            [
                "Stuart Say",
                mark_safe(HTML.tag("Declined", Colour.ORANGE).html)
            ],
            ["Laura Frith",
             mark_safe(HTML.tag("Waiting", Colour.PINK).html)],
            [
                "Emma Tennant",
                mark_safe(HTML.tag("New", Colour.TURQUOISE).html)
            ],
            [
                "Nigel Starmer",
                mark_safe(HTML.tag("Delayed", Colour.YELLOW).html)
            ],
        ]

        self.helper = FormHelper()
        self.helper.layout = Layout(HTML.table(headings, statuses))
コード例 #23
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        headings = ["Case manager", "Cases opened", "Cases closed"]
        past_day = [
            ["David Francis", "3", "0"],
            ["Paul Farmer", "1", "0"],
            ["Rita Patel", "2", "0"],
        ]
        past_week = [
            ["David Francis", "24", "18"],
            ["Paul Farmer", "16", "20"],
            ["Rita Patel", "24", "27"],
        ]
        past_month = [
            ["David Francis", "98", "95"],
            ["Paul Farmer", "122", "131"],
            ["Rita Patel", "126", "142"],
        ]
        past_year = [
            ["David Francis", "1380", "1472"],
            ["Paul Farmer", "1129", "1083"],
            ["Rita Patel", "1539", "1265"],
        ]

        self.helper = FormHelper()
        self.helper.layout = Layout(
            Tabs(
                TabPanel(
                    "Past day",
                    HTML.h1("Past day"),
                    HTML.table(headings, past_day),
                ),
                TabPanel(
                    "Past week",
                    HTML.h1("Past week"),
                    HTML.table(headings, past_week),
                ),
                TabPanel(
                    "Past month",
                    HTML.h1("Past month"),
                    HTML.table(headings, past_month),
                ),
                TabPanel(
                    "Past year",
                    HTML.h1("Past year"),
                    HTML.table(headings, past_year),
                ),
            ))
コード例 #24
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.helper = FormHelper()

        self.helper.layout = Layout(
            Field.text("order_number", label_size=Size.SMALL),
            Field.text("origin", label_size=Size.SMALL),
            Field.radios("mechanism", legend_size=Size.SMALL),
            Field.radios("category", legend_size=Size.SMALL),
            Button("submit", "Search and Filter", css_class="govuk-!-margin-top-6"),
            HTML(
                f'<a class="govuk-button govuk-button--secondary govuk-!-margin-top-6" href="{self.clear_url}"> Clear </a>',
            ),
        )
コード例 #25
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.helper = FormHelper()

        field_layout = (
            field_to_layout(field_name, field)
            for field_name, field in self.fields.items()
        )

        self.helper.layout = Layout(
            *field_layout,
            Button("submit", "Search and Filter"),
            HTML(
                f'<a class="govuk-button govuk-button--secondary" href="{self.clear_url}"> Clear </a>',
            ),
        )
コード例 #26
0
ファイル: forms.py プロジェクト: ahernp/crispy-forms-gds
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        header = ["Case worker", "Number of cases closed"]
        rows = [["David Francis", 3], ["Paul Farmer", 1]]
        header_css = [
            "govuk-!-width-one-half",
            "govuk-!-width-one-half govuk-table__header--numeric",
        ]
        row_css = ["", "govuk-table__cell--numeric"]

        self.helper = FormHelper()
        self.helper.layout = Layout(
            HTML.table(
                header, rows, caption="Caption", header_css=header_css, row_css=row_css
            )
        )
コード例 #27
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        kwargs.pop("initial")

        self.fields["geo_area"].initial = self.data.get(f"{self.prefix}-geo_area")

        geographical_area_fields = {
            GeoAreaType.ERGA_OMNES: self.erga_omnes_instance,
            GeoAreaType.GROUP: self.data.get(f"{self.prefix}-geographical_area_group"),
            GeoAreaType.COUNTRY: self.data.get(
                f"{self.prefix}-geographical_area_country_or_region",
            ),
        }

        nested_forms_initial = {}

        if self.fields["geo_area"].initial:
            nested_forms_initial["geographical_area"] = geographical_area_fields[
                self.fields["geo_area"].initial
            ]

        self.bind_nested_forms(*args, initial=nested_forms_initial, **kwargs)

        self.helper = FormHelper(self)
        self.helper.label_size = Size.SMALL
        self.helper.legend_size = Size.SMALL
        self.helper.layout = Layout(
            "geo_area",
            HTML.details(
                "Help with geography",
                (
                    "Choose the geographical area to which the measure applies. This can be a specific country "
                    "or a group of countries, and exclusions can be specified. The measure will only apply to imports "
                    "from or exports to the selected area."
                ),
            ),
            Submit(
                "submit",
                "Continue",
                data_module="govuk-button",
                data_prevent_double_click="true",
            ),
        )
コード例 #28
0
    def __init__(self, *args, **kwargs):
        # remove measure_start_date from kwargs here because superclass will not be expecting it
        self.measure_start_date = kwargs.pop("measure_start_date")
        super().__init__(*args, **kwargs)

        self.helper = FormHelper(self)
        self.helper.form_tag = False
        self.helper.label_size = Size.SMALL
        self.helper.layout = Layout(
            Fieldset(
                "commodity",
                "duties",
                HTML(
                    loader.render_to_string(
                        "components/duty_help.jinja",
                        context={"component": "measure"},
                    ), ),
                Field("DELETE",
                      template="includes/common/formset-delete-button.jinja")
                if not self.prefix.endswith("__prefix__") else None,
            ), )
コード例 #29
0
 def valid_layout(self):
     message = 'You clicked the "%s" button.' % self.get_button()
     self.helper.layout = Layout(HTML.p(message),
                                 Button("continue", "Continue"))