Пример #1
0
def test_threshold():
    """Verify info is shown after a certain number of words has been entered."""
    form = TextareaForm(initial={"description": "Field value"})
    form.helper = FormHelper()
    form.helper.layout = Layout(
        Field.textarea("description", max_words=100, threshold=50))
    assert parse_form(form) == parse_contents(RESULT_DIR, "threshold.html")
Пример #2
0
def test_small():
    """Verify size of the radio buttons can be changed."""
    form = RadiosForm()
    form.helper = FormHelper()
    form.helper.layout = Layout(Field("method", context={"radios_small":
                                                         True}))
    assert parse_form(form) == parse_contents(RESULT_DIR, "buttons_small.html")
Пример #3
0
def test_show_label_as_heading():
    """Verify the field label can be displayed as the page heading."""
    form = TextareaForm()
    form.helper = FormHelper()
    form.helper.layout = Layout(
        Field("description", context={"label_tag": "h1"}))
    assert parse_form(form) == parse_contents(RESULT_DIR, "label_heading.html")
Пример #4
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.helper.layout = Layout(
         Fieldset(
             "regulation_usage",
             "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",
             Field(
                 "sequence_number",
                 css_class="govuk-input govuk-input--width-5",
             ),
             self._load_details_from_template(
                 "Help with sequence number",
                 "regulations/help_sequence_number.jinja",
             ),
             "approved",
         ),
         Submit("submit", "Save"),
     )
Пример #5
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."
         ))
Пример #6
0
    def __init__(self, *args, **kwargs):
        super(DateInputForm, self).__init__(*args, **kwargs)
        self.helper = FormHelper()
        self.helper.layout = Layout("date", Button("submit", _("Submit")))

        self.fields["date"].fields[2].error_messages[
            "incomplete"] = "The date your passport was issued must include a year"
Пример #7
0
def test_change_legend_size():
    """Verify size of the field legend can be changed from the default."""
    form = CheckboxesForm()
    form.helper = FormHelper()
    form.helper.layout = Layout(
        Field("method", context={"legend_size": Size.for_legend("l")}))
    assert parse_form(form) == parse_contents(RESULT_DIR, "legend_size.html")
Пример #8
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.fields["footnote_type"].label_from_instance = (
            lambda obj: f"{obj.footnote_type_id} - {obj.description}")
        self.fields["footnote_type"].label = "Footnote type"
        self.fields["footnote_type"].required = False

        if self.instance:
            self.fields["code"].disabled = True
            self.fields["code"].help_text = "You can't edit this"
            self.fields["code"].initial = str(self.instance)

            self.fields["footnote_type"].disabled = True
            self.fields["footnote_type"].help_text = "You can't edit this"

            if self.instance.valid_between.lower:
                self.fields[
                    "start_date"].initial = self.instance.valid_between.lower
            if self.instance.valid_between.upper:
                self.fields[
                    "end_date"].initial = self.instance.valid_between.upper

        self.helper = FormHelper(self)
        self.helper.layout = Layout(
            Field.text(
                "code",
                field_width=Fixed.TEN,
                label_size=Size.SMALL,
            ),
            Field("footnote_type", context={"label_size": "govuk-label--s"}),
            Field("start_date", context={"legend_size": "govuk-label--s"}),
            Field("end_date", context={"legend_size": "govuk-label--s"}),
            Submit("submit", "Save"),
        )
Пример #9
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.helper = FormHelper()
     self.helper.layout = Layout(
         "sort_by",
         Button("submit", "Submit"),
     )
Пример #10
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.helper = FormHelper()
     self.helper.layout = Layout(
         Field.checkboxes("method", legend_size=Size.MEDIUM, small=True),
         Button("submit", "Submit"),
     )
Пример #11
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.fields["footnote_type"].label_from_instance = (
            lambda obj: f"{obj.footnote_type_id} - {obj.description}")
        self.fields["footnote_type"].label = "Footnote type"
        self.fields["footnote_type"].required = False

        if self.instance:
            self.fields["code"].disabled = True
            self.fields["code"].help_text = "You can't edit this"
            self.fields["code"].initial = str(self.instance)

            self.fields["footnote_type"].disabled = True
            self.fields["footnote_type"].help_text = "You can't edit this"

        self.helper = FormHelper(self)
        self.helper.label_size = Size.SMALL
        self.helper.legend_size = Size.SMALL

        self.helper.layout = Layout(
            Field.text(
                "code",
                field_width=Fixed.TEN,
            ),
            Field("footnote_type"),
            Field("start_date"),
            Field("end_date"),
            Submit(
                "submit",
                "Save",
                data_module="govuk-button",
                data_prevent_double_click="true",
            ),
        )
Пример #12
0
def test_checkbox_size():
    """Verify size of the checkbox can be changed from the default."""
    form = CheckboxForm()
    form.helper = FormHelper()
    form.helper.layout = Layout(
        Field("accept", context={"checkboxes_small": True}))
    assert parse_form(form) == parse_contents(RESULT_DIR, "checkbox_size.html")
Пример #13
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. "))
Пример #14
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.helper = FormHelper()
     self.helper.layout = Layout(
         Field.textarea("description", rows=3, max_words=100,),
         Button("submit", "Submit"),
     )
Пример #15
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.helper = FormHelper(self)
        self.helper.form_tag = False

        self.helper.layout = Layout(
            Fieldset(
                Div(
                    Field(
                        "condition_code",
                        template="components/measure_condition_code/template.jinja",
                    ),
                    "condition_sid",
                ),
                Div(
                    Field("reference_price", css_class="govuk-input"),
                    "required_certificate",
                    css_class="govuk-radios__conditional",
                ),
                Field(
                    "action",
                    template="components/measure_condition_action_code/template.jinja",
                ),
                Div(
                    MeasureConditionComponentDuty("applicable_duty"),
                ),
                Field("DELETE", template="includes/common/formset-delete-button.jinja")
                if not self.prefix.endswith("__prefix__")
                else None,
                legend="Condition code",
                legend_size=Size.SMALL,
                data_field="condition_code",
            ),
        )
Пример #16
0
def test_change_label_size():
    """Verify size of the field label can be changed from the default."""
    form = FileUploadForm()
    form.helper = FormHelper()
    form.helper.layout = Layout(
        Field("file", context={"label_size": Size.for_label("l")}))
    assert parse_form(form) == parse_contents(RESULT_DIR, "label_size.html")
Пример #17
0
def test_change_legend_size():
    """Verify size of the field legend can be changed from the default."""
    form = FieldsetForm()
    form.helper = FormHelper()
    form.helper.layout = Layout(
        Fieldset("name", "email", legend="Contact", legend_size=Size.LARGE))
    assert parse_form(form) == parse_contents(RESULT_DIR, "legend_size.html")
Пример #18
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",
         ),
     )
Пример #19
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.fields[
            "certificate_type"].label_from_instance = lambda obj: f"{obj.sid} - {obj.description}"
        self.fields["certificate_type"].required = False

        if self.instance:
            self.fields["code"].disabled = True
            self.fields["code"].help_text = "You can't edit this"
            self.fields["code"].initial = self.instance.code

            self.fields["certificate_type"].disabled = True
            self.fields["certificate_type"].help_text = "You can't edit this"

        self.helper = FormHelper(self)
        self.helper.label_size = Size.SMALL
        self.helper.legend_size = Size.SMALL

        self.helper.layout = Layout(
            Field.text(
                "code",
                field_width=Fixed.TEN,
            ),
            "certificate_type",
            "start_date",
            "end_date",
            Submit("submit", "Save"),
        )
Пример #20
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."),
             ),
         ))
Пример #21
0
def test_show_legend_as_heading():
    """Verify the field legend can be displayed as the page heading."""
    form = CheckboxesForm()
    form.helper = FormHelper()
    form.helper.layout = Layout(Field("method", context={"legend_tag": "h1"}))
    assert parse_form(form) == parse_contents(RESULT_DIR,
                                              "legend_heading.html")
Пример #22
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")
Пример #23
0
 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>")),
         ))
Пример #24
0
 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"),
     )
Пример #25
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")
Пример #26
0
 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"),
     )
Пример #27
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"})),
     )
Пример #28
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"),
     )
Пример #29
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.helper = FormHelper()

        self.helper.layout = Layout(
            *self.fields,
            Button("submit", "Upload"),
        )
Пример #30
0
def test_show_legend_as_heading():
    """Verify the field legend can be displayed as the page heading."""
    form = FieldsetForm()
    form.helper = FormHelper()
    form.helper.layout = Layout(
        Fieldset("name", "email", legend="Contact", legend_tag="h1"))
    assert parse_form(form) == parse_contents(RESULT_DIR,
                                              "legend_heading.html")