Example #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")
Example #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")
Example #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")
Example #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"),
     )
Example #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."
         ))
Example #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"
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")
Example #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"),
        )
Example #9
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.helper = FormHelper()
     self.helper.layout = Layout(
         "sort_by",
         Button("submit", "Submit"),
     )
Example #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"),
     )
Example #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",
            ),
        )
Example #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")
Example #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. "))
Example #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"),
     )
Example #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",
            ),
        )
Example #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")
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")
Example #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",
         ),
     )
Example #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"),
        )
Example #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."),
             ),
         ))
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")
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")
Example #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>")),
         ))
Example #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"),
     )
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")
Example #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"),
     )
Example #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"})),
     )
Example #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"),
     )
Example #29
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.helper = FormHelper()

        self.helper.layout = Layout(
            *self.fields,
            Button("submit", "Upload"),
        )
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")