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"), )
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", ), )
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", ), )
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.fields[ "type" ].label_from_instance = lambda obj: f"{obj.sid} - {obj.description}" self.fields["type"].label = "Additional code type" self.fields["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 = f"{self.instance.type.sid}{self.instance.code}" self.fields["type"].disabled = True self.fields["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("type"), Field("start_date"), Field("end_date"), Submit("submit", "Save"), )
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"), )
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")
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")
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", ), )
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 = 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")
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")
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_inline(): """Verify radio buttons can be displayed in a row.""" form = RadiosForm() form.helper = FormHelper() form.helper.layout = Layout( Field("method", context={"radios_inline": True})) assert parse_form(form) == parse_contents(RESULT_DIR, "buttons_inline.html")
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.helper.layout.insert( 0, Field( "described_certificate", type="hidden", ), ) self.fields["description"].label = "Certificate description"
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.helper.layout.insert( 0, Field( "described_geographicalarea", type="hidden", ), ) self.fields["description"].label = "Geographical area description"
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.helper.layout.insert( 0, Field( "described_additionalcode", type="hidden", ), ) self.fields["description"].label = "Additional code description"
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.helper = FormHelper(self) self.helper.layout = Layout( Field("validity_start", context={"legend_size": "govuk-label--s"}), Field.textarea("description", label_size=Size.SMALL, rows=5), Submit( "submit", "Save", data_module="govuk-button", data_prevent_double_click="true", ), )
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) 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("start_date", context={"legend_size": "govuk-label--s"}), Field.textarea("description", label_size=Size.SMALL, rows=5), Submit("submit", "Save"), )
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.helper = FormHelper(self) self.helper.form_tag = False self.helper.legend_size = Size.SMALL self.helper.layout = Layout( Fieldset( "footnote", Field("DELETE", template="includes/common/formset-delete-button.jinja") if not self.prefix.endswith("__prefix__") else None, legend="Footnote", legend_size=Size.SMALL, ), )
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, ), )
def test_text_new_fluid_width(): field = Field("name", css_class=Fluid.for_input("one-fifth", validate=False)) assert field.attrs["class"] == "govuk-!-width-one-fifth" assert field.context == {}
def test_text_new_fixed_width(): field = Field("name", css_class=Fixed.for_input(1, validate=False)) assert field.attrs["class"] == "govuk-input--width-1" assert field.context == {}