def reissue_ogl_confirmation_form(case_id, queue_id): return Form( title=Manage.ReissueOGL.TITLE, description=Manage.ReissueOGL.DESCRIPTION, questions=[ RadioButtons( name="confirm", options=[ Option(key=True, value=Manage.ReissueOGL.YES), Option(key=False, value=Manage.ReissueOGL.NO) ], classes=["govuk-checkboxes--inline"], ), DetailComponent( title=Manage.ReissueOGL.NOTE, components=[ TextArea(name="note", classes=["govuk-!-margin-0"]) ], ), ], back_link=BackLink(url=reverse("cases:case", kwargs={ "queue_pk": queue_id, "pk": case_id })), default_button_name=Manage.ReissueOGL.SUBMIT, container="case", )
def assign_users_form(request: HttpRequest, team_id, queue, multiple: bool): params = { "teams": team_id, "disable_pagination": True, "status": UserStatuses.ACTIVE } return Form( title=cases.Manage.AssignUsers.MULTIPLE_TITLE if multiple else cases.Manage.AssignUsers.TITLE, description=cases.Manage.AssignUsers.DESCRIPTION, questions=[ Filter(), Checkboxes("users", options=get_gov_users( request, params, convert_to_options=True, ), filterable=True), DetailComponent( title=cases.Manage.AssignUsers.NOTE, components=[ TextArea(name="note", classes=["govuk-!-margin-0"]), ], ), ], caption=queue["name"], default_button_name=cases.Manage.AssignUsers.BUTTON, )
def done_with_case_form(request, queue_pk, case_pk, has_review_date): queue = None queues, _ = get_user_case_queues(request, case_pk) if not queues: queue = get_queue(request, queue_pk) return Form( title=DoneWithCaseOnQueueForm.TITLE if not queue else DoneWithCaseOnQueueForm.TITLE_SINGULAR.format(queue["name"]), questions=[ conditional( queues, Checkboxes( name="queues[]", options=[ Option(queue["id"], queue["name"]) for queue in queues ], title=DoneWithCaseOnQueueForm.CHECKBOX_TITLE, description=DoneWithCaseOnQueueForm.CHECKBOX_DESCRIPTION, ), HiddenField(name="queues[]", value=queue_pk), ), DetailComponent( title=DoneWithCaseOnQueueForm.NOTE, components=[ TextArea(name="note", classes=["govuk-!-margin-0"]), ], ), ], default_button_name=DoneWithCaseOnQueueForm.SUBMIT, container="case", javascript_imports=conditional(has_review_date, {"/javascripts/assign_queue.js"}, None), )
def set_flags_form(flags, level, show_case_header=False, show_sidebar=False): form = Form( title=getattr(SetFlagsForm, level).TITLE, description=getattr(SetFlagsForm, level).DESCRIPTION, questions=[ Filter(placeholder=getattr(SetFlagsForm, level).FILTER), Checkboxes( name="flags[]", options=flags, filterable=True, disabled_hint="You do not have permission to remove this flag.", ), DetailComponent( title=getattr(SetFlagsForm, level).Note.TITLE, components=[ TextArea(name="note", classes=["govuk-!-margin-0"]), ], ), ], default_button_name=getattr(SetFlagsForm, level).SUBMIT_BUTTON, container="case" if show_case_header else "two-pane", javascript_imports={"/javascripts/flags-permission-hints.js"}, ) if show_sidebar: form.helpers = [ HelpSection("Setting flags on:", "", includes="case/includes/selection-sidebar.html") ] return form
def review_goods_form(request, is_goods_type, **kwargs): return Form( title=cases.ReviewGoodsForm.HEADING, questions=[ RadioButtons( title=goods.ReviewGoods.IS_GOOD_CONTROLLED, name="is_good_controlled", options=[ Option( key=conditional(is_goods_type, True, "yes"), value="Yes", components=[ control_list_entries_question( control_list_entries=get_control_list_entries( request, convert_to_options=True), title=goods.ReviewGoods.ControlListEntries. TITLE, ), PicklistPicker( target="report_summary", title=goods.ReviewGoods.ReportSummary.TITLE, description=goods.ReviewGoods.ReportSummary. DESCRIPTION, type=PicklistCategories.report_summary.key, set_text=False, ), ], ), Option(key=conditional(is_goods_type, False, "no"), value="No"), ], ), DetailComponent( title=goods.ReviewGoods.Comment.TITLE, components=[ TextArea(name="comment", extras={ "max_length": 500, }), ], ), ], default_button_name=cases.ReviewGoodsForm.CONFIRM_BUTTON, container="case", back_link=BackLink(url=reverse("cases:case", kwargs={ "queue_pk": kwargs["queue_pk"], "pk": kwargs["pk"] })), helpers=[ HelpSection(goods.ReviewGoods.GIVING_ADVICE_ON, "", includes="case/includes/selection-sidebar.html") ], )
def export_type_form(): options = [ Option( key=CaseTypes.SIEL, value="Standard Individual Export Licence (SIEL)", description= ("Select to apply for a licence to export a set quantity and set value of products to 1 destination." ), ), Option( key=CaseTypes.OGEL, value="Open General Export Licence (OGEL)", description= ("Select to register a pre-published licence with set terms " "and conditions. Being an OGEL holder can benefit your business " "by saving time and money."), disabled=settings.FEATURE_FLAG_ONLY_ALLOW_SIEL, ), Option( key=CaseTypes.OIEL, value="Open Individual Export Licence (OIEL)", description= ("Select to apply for a licence to export multiple shipments of specific products to specific " "destinations. OIELs cover long term projects and repeat business." ), disabled=settings.FEATURE_FLAG_ONLY_ALLOW_SIEL, ), ] help_url = "https://www.gov.uk/guidance/beginners-guide-to-export-controls#what-licence-do-i-need" if settings.FEATURE_FLAG_ONLY_ALLOW_SIEL: description = render_to_string( "applications/use-spire-application-type.html") else: description = "" return Form( title="Select the type of export licence you need", description=description, questions=[ RadioButtons(name="application_type", options=options), DetailComponent( "What licence do I need?", f"Read about the [different types of export control licences]({help_url})." ), ], default_button_name="Continue", back_link=BackLink("Back", reverse("apply_for_a_licence:start")), )
def review_goods_form(control_list_entries, back_url): return Form( title=cases.ReviewGoodsForm.HEADING, questions=[ RadioButtons( title=goods.ReviewGoods.IS_GOOD_CONTROLLED, name="is_good_controlled", options=[ Option(key=True, value="Yes"), Option(key=False, value="No"), ], ), control_list_entries_question( control_list_entries=control_list_entries, title=goods.ReviewGoods.ControlListEntries.TITLE, ), PicklistPicker( target="report_summary", title=goods.ReviewGoods.ReportSummary.TITLE, description=goods.ReviewGoods.ReportSummary.DESCRIPTION, type=PicklistCategories.report_summary.key, set_text=False, allow_clear=True, ), DetailComponent( title=goods.ReviewGoods.Comment.TITLE, components=[ TextArea(name="comment", extras={"max_length": 500}) ], ), ], default_button_name=cases.ReviewGoodsForm.CONFIRM_BUTTON, container="case", back_link=BackLink(url=back_url), helpers=[ HelpSection(goods.ReviewGoods.GIVING_ADVICE_ON, "", includes="case/includes/selection-sidebar.html") ], )
def generate_documents_form(queue_pk, case_pk): return Form( title=GenerateGoodsDecisionForm.TITLE, questions=[ Custom("components/finalise-generate-documents.html"), DetailComponent( title=GenerateGoodsDecisionForm.NOTE, components=[ TextArea(title=GenerateGoodsDecisionForm.NOTE_DESCRIPTION, name="note", classes=["govuk-!-margin-0"]), ], ), ], back_link=BackLink(url=reverse("cases:finalise", kwargs={ "queue_pk": queue_pk, "pk": case_pk })), container="case", default_button_name=GenerateGoodsDecisionForm.BUTTON, )
def open_licence_return_form_group(): return FormGroup([ Form( title=OpenReturnsHelpPage.TITLE, questions=[ Label(OpenReturnsHelpPage.DESCRIPTION), DetailComponent(OpenReturnsHelpPage.FORMATTING_HELP_LINK, OpenReturnsHelpPage.FORMATTING_HELP_DETAILS), ], default_button_name=OpenReturnsHelpPage.BUTTON, back_link=BackLink(OpenReturnsHelpPage.BACK, reverse_lazy("core:home")), ), Form( title=OpenReturnsForm.Year.TITLE, description=OpenReturnsForm.Year.DESCRIPTION, questions=[ Select( title=OpenReturnsForm.Year.FIELD_TITLE, description=OpenReturnsForm.Year.FIELD_DESCRIPTION, name="year", options=get_years(), ) ], default_button_name=OpenReturnsForm.Year.BUTTON, ), Form( title=OpenReturnsForm.Upload.TITLE, description=OpenReturnsForm.Upload.DESCRIPTION, questions=[ FileUpload(), Label(OpenReturnsForm.Upload.ExampleTable.HEADING), Custom("components/spreadsheet.html"), ], default_button_name=OpenReturnsForm.Upload.BUTTON, ), ])
def users_team_queues(request, queue_pk, case_pk, user_pk): queues = get_users_team_queues(request, user_pk, True) return Form( title=cases.Manage.AssignUserAndQueue.QUEUE_TITLE, description=cases.Manage.AssignUserAndQueue.QUEUE_DESCRIPTION, questions=[ Filter(), RadioButtons("queue", queues, filterable=True), HiddenField("user_pk", user_pk), HiddenField("case_pk", case_pk), DetailComponent( title=cases.Manage.AssignUserAndQueue.NOTE, components=[ TextArea(name="note", classes=["govuk-!-margin-0"]), ], ), ], back_link=BackLink(url=reverse_lazy("cases:assign_user", kwargs={ "queue_pk": queue_pk, "pk": case_pk })), container="case", )
def test_detail_component(self): detail = DetailComponent(title="abc", description=self.markdown_description) self.assertEqual(detail.description, self.html_description)
def export_licence_questions(request, application_type, goodstype_category=None): should_display_firearms_question = goodstype_category in [ GoodsTypeCategory.MILITARY, GoodsTypeCategory.UK_CONTINENTAL_SHELF, ] return FormGroup([ Form( title=ExportLicenceQuestions.ExportLicenceQuestion.TITLE, description=ExportLicenceQuestions.ExportLicenceQuestion. DESCRIPTION, questions=[ RadioButtons( name="application_type", options=[ Option( key=CaseTypes.OGEL, value=ExportLicenceQuestions.ExportLicenceQuestion. OPEN_GENERAL_EXPORT_LICENCE, description=ExportLicenceQuestions. ExportLicenceQuestion. OPEN_GENERAL_EXPORT_LICENCE_DESCRIPTION, ), Option( key=CaseTypes.SIEL, value=ExportLicenceQuestions.ExportLicenceQuestion. STANDARD_LICENCE, description=ExportLicenceQuestions. ExportLicenceQuestion.STANDARD_LICENCE_DESCRIPTION, ), Option( key=CaseTypes.OIEL, value=ExportLicenceQuestions.ExportLicenceQuestion. OPEN_LICENCE, description=ExportLicenceQuestions. ExportLicenceQuestion.OPEN_LICENCE_DESCRIPTION, ), ], ), DetailComponent( InitialApplicationQuestionsForms.OpeningQuestion. HELP_WITH_CHOOSING_A_LICENCE, InitialApplicationQuestionsForms.OpeningQuestion. HELP_WITH_CHOOSING_A_LICENCE_CONTENT, ), ], default_button_name=generic.CONTINUE, back_link=BackLink( ExportLicenceQuestions.ExportLicenceQuestion.BACK, reverse_lazy("apply_for_a_licence:start")), ), *conditional(application_type == CaseTypes.OIEL, [goodstype_category_form()], []), *conditional( application_type != CaseTypes.OGEL and goodstype_category not in ["media", "cryptographic"], [ Form( title=ExportLicenceQuestions.ExportType.TITLE, description=ExportLicenceQuestions.ExportType.DESCRIPTION, questions=[ RadioButtons( name="export_type", options=[ Option( "temporary", ExportLicenceQuestions. ExportType.TEMPORARY), Option( "permanent", ExportLicenceQuestions. ExportType.PERMANENT), ], ), ], default_button_name=generic.CONTINUE if application_type == CaseTypes.SIEL else generic.SAVE_AND_CONTINUE, ), ], [], ), *conditional(application_type != CaseTypes.OGEL, [reference_name_form()], []), *conditional(application_type == CaseTypes.SIEL, [told_by_an_official_form()], []), *conditional(should_display_firearms_question, [firearms_form()], []), ])
from django.urls import reverse from lite_content.lite_internal_frontend.cases import Manage from lite_forms.components import Form, Checkboxes, Filter, BackLink, DetailComponent, TextArea from queues.services import get_queues def move_case_form(request: HttpRequest, queue, case: dict): return Form( title=Manage.MoveCase.TITLE, description=Manage.MoveCase.DESCRIPTION, questions=[ Filter(), Checkboxes("queues[]", get_queues(request, convert_to_options=True), filterable=True), DetailComponent( title=Manage.MoveCase.NOTE, components=[ TextArea(name="note", classes=["govuk-!-margin-0"]), ], ), ], back_link=BackLink(url=reverse("cases:case", kwargs={ "queue_pk": queue["id"], "pk": case["id"] })), container="case", )
def respond_to_grading_query_form(request, queue_pk, case): pv_gradings = get_gov_pv_gradings(request, convert_to_options=True) return Form( title=PVGradingForm.TITLE, description=PVGradingForm.DESCRIPTION, questions=[ Heading(PVGradingForm.HEADING, HeadingStyle.S), Summary( values={ PVGradingForm.Summary.DESCRIPTION: case.data["good"]["description"], PVGradingForm.Summary.PART_NUMBER: default_na(case.data["good"]["part_number"]), PVGradingForm.Summary.IS_THIS_GOOD_CONTROLLED: case.data["good"]["is_good_controlled"]["value"], PVGradingForm.Summary.CONTROL_LIST_ENTRIES: case.data["clc_control_list_entry"], PVGradingForm.Summary.EXPLANATION: case.data["clc_raised_reasons"], }, classes=[ "govuk-inset-text", "govuk-summary-list--no-border", "govuk-!-padding-top-0", "govuk-!-padding-bottom-0", "govuk-!-padding-left-6", ], ), Heading(PVGradingForm.YOUR_RESPONSE, HeadingStyle.S), Group( components=[ TextInput(title=PVGradingForm.Grading.PREFIX, name="prefix", optional=True), Select( # request not supplied since static endpoints don't require it. options=pv_gradings, title=PVGradingForm.Grading.GRADING, name="grading", ), TextInput(title=PVGradingForm.Grading.SUFFIX, name="suffix", optional=True), ], classes=["app-pv-grading-inputs"], ), DetailComponent( title=PVGradingForm.COMMENT, components=[ TextArea( name="comment", extras={ "max_length": 500, }, ), ], ), ], default_button_name=PVGradingForm.SUBMIT_BUTTON, back_link=BackLink(url=reverse_lazy("cases:case", kwargs={ "queue_pk": queue_pk, "pk": case["id"] }), ), container="case", )
description=CLCReviewGoods.ReportSummary. DESCRIPTION, type=PicklistCategories.report_summary.key, set_text=False, ), ], ), Option(key=False, value="no"), ], ), DetailComponent( title=PVGradingForm.COMMENT, components=[ TextArea( name="comment", extras={ "max_length": 500, }, ), ], ), ], default_button_name=CLCReviewGoods.SUBMIT_BUTTON, back_link=BackLink(url=reverse_lazy("cases:case", kwargs={ "queue_pk": queue_pk, "pk": case["id"] }), ), container="case", )
def test_remove_unused_errors(self): form = Form(questions=[TextInput("name"), TextInput("age"), TextInput("password"), DetailComponent("", ""),]) errors = { "name": "This field must not be empty", "email": "This field must not be empty", "age": "This field must not be empty", "password": "******", } cleaned_errors = { "name": "This field must not be empty", "age": "This field must not be empty", "password": "******", } self.assertEqual(cleaned_errors, remove_unused_errors(errors, form))
from django.urls import reverse from lite_content.lite_internal_frontend import cases from lite_forms.components import Form, Option, Select, BackLink, TextArea, DetailComponent def change_status_form(queue, case, statuses): return Form( title=cases.ChangeStatusPage.TITLE, description=cases.ChangeStatusPage.DESCRIPTION, questions=[ Select( name="status", options=[Option(status["key"], status["value"]) for status in statuses], include_default_select=False, ), DetailComponent( title=cases.ChangeStatusPage.NOTE, components=[TextArea(name="note", classes=["govuk-!-margin-0"]),], ), ], back_link=BackLink(url=reverse("cases:case", kwargs={"queue_pk": queue["id"], "pk": case["id"]})), container="case", )