Exemplo n.º 1
0
def raise_a_goods_query(good_id, raise_a_clc: bool, raise_a_pv: bool):
    questions = []

    if raise_a_clc:
        if GoodsQueryForm.CLCQuery.TITLE:
            questions += [
                Heading(GoodsQueryForm.CLCQuery.TITLE, HeadingStyle.M),
            ]
        questions += [
            TextInput(
                title=GoodsQueryForm.CLCQuery.Code.TITLE,
                description=GoodsQueryForm.CLCQuery.Code.DESCRIPTION,
                name="clc_control_code",
                optional=True,
            ),
            TextArea(title=GoodsQueryForm.CLCQuery.Details.TITLE, name="clc_raised_reasons", optional=True,),
        ]

    if raise_a_pv:
        if GoodsQueryForm.PVGrading.TITLE:
            questions += [
                Heading(GoodsQueryForm.PVGrading.TITLE, HeadingStyle.M),
            ]
        questions += [
            TextArea(title=GoodsQueryForm.PVGrading.Details.TITLE, name="pv_grading_raised_reasons", optional=True,),
        ]

    return Form(
        title=GoodsQueryForm.TITLE,
        description=GoodsQueryForm.DESCRIPTION,
        questions=questions,
        back_link=BackLink(GoodsQueryForm.BACK_LINK, reverse("goods:good", kwargs={"pk": good_id})),
        default_button_name="Save",
    )
Exemplo n.º 2
0
def edit_address_questions_form(is_commercial,
                                in_uk,
                                countries,
                                prefix="site.address."):
    phone_number_label = "Organisation phone number" if is_commercial else "Phone number"

    if in_uk:
        questions = [
            TextInput(title=RegisterAnOrganisation.NAME_OF_SITE,
                      name="site.name"),
            Heading(RegisterAnOrganisation.WhereIsTheExporterBased.TITLE,
                    HeadingStyle.M),
            TextInput(
                title="Building and street",
                accessible_description="line 1 of 2",
                name=prefix + "address_line_1",
            ),
            TextInput(
                title="",
                accessible_description="line 2 of 2",
                name=prefix + "address_line_2",
            ),
            TextInput(title="Town or city", name=prefix + "city"),
            TextInput(title="County or state", name=prefix + "region"),
            TextInput(title="Postcode", name=prefix + "postcode"),
        ]
    else:
        questions = [
            TextInput(title=RegisterAnOrganisation.NAME_OF_SITE,
                      name="site.name"),
            Heading(RegisterAnOrganisation.WhereIsTheExporterBased.TITLE,
                    HeadingStyle.M),
            TextArea(title="Address",
                     name=prefix + "address",
                     classes=["govuk-input--width-20"],
                     rows=6),
        ]

    return Form(
        title="Edit default site for this exporter",
        questions=questions + [
            TextInput(
                title=phone_number_label,
                name="phone_number",
                description=
                "For international numbers include the country code",
            ),
            TextInput(title="Website", name="website", optional=True),
            conditional(
                not in_uk,
                AutocompleteInput(title="Country",
                                  name=prefix + "country",
                                  options=countries)),
        ],
    )
Exemplo n.º 3
0
def pv_details_form(request):
    return Form(
        title=GoodGradingForm.TITLE,
        description=GoodGradingForm.DESCRIPTION,
        questions=[
            Heading("PV grading", HeadingStyle.M),
            Group(
                components=[
                    TextInput(title=GoodGradingForm.PREFIX, name="prefix", optional=True),
                    Select(
                        options=get_pv_gradings(request, convert_to_options=True),
                        title=GoodGradingForm.GRADING,
                        name="grading",
                        optional=True,
                    ),
                    TextInput(title=GoodGradingForm.SUFFIX, name="suffix", optional=True),
                ],
                classes=["app-pv-grading-inputs"],
            ),
            TextInput(title=GoodGradingForm.OTHER_GRADING, name="custom_grading", optional=True),
            TextInput(title=GoodGradingForm.ISSUING_AUTHORITY, name="issuing_authority"),
            TextInput(title=GoodGradingForm.REFERENCE, name="reference"),
            DateInput(
                title=GoodGradingForm.DATE_OF_ISSUE, prefix="date_of_issue", name="date_of_issue", optional=False
            ),
        ],
        default_button_name=GoodGradingForm.BUTTON,
    )
Exemplo n.º 4
0
def create_default_site_form(request, in_uk):
    return Form(
        title=RegisterAnOrganisation.CREATE_DEFAULT_SITE,
        questions=[
            TextInput(title=RegisterAnOrganisation.NAME_OF_SITE, name="site.name"),
            Heading(RegisterAnOrganisation.WhereIsTheExporterBased.TITLE, HeadingStyle.M),
            *conditional(
                in_uk,
                address_questions(None, "site.address."),
                foreign_address_questions(get_countries(request, True, ["GB"]), "site.address."),
            ),
        ],
        default_button_name=strings.CONTINUE,
    )
Exemplo n.º 5
0
def register_hmrc_organisation_forms():
    return FormGroup(
        [
            Form(
                title="Register an HMRC organisation",
                questions=[
                    HiddenField(name="type", value="hmrc"),
                    TextInput(title="Name of HMRC organisation", name="name"),
                    TextInput(title=RegisterAnOrganisation.NAME_OF_SITE, name="site.name"),
                    Heading("Where are they based?", HeadingStyle.M),
                    *address_questions(None, "site.address."),
                ],
                default_button_name="Continue",
            ),
            create_admin_user_form(),
        ],
        show_progress_indicators=True,
    )
Exemplo n.º 6
0
def new_site_forms(request):
    in_uk = request.POST.get("location", "").lower() == "united_kingdom"
    sites = []
    if request.POST.get("address.postcode"):
        sites = get_sites(request,
                          request.user.organisation,
                          postcode=request.POST.get("address.postcode"))

    return FormGroup([
        Form(
            caption="Step 1 of 4",
            title=AddSiteForm.WhereIsYourSiteBased.TITLE,
            description=AddSiteForm.WhereIsYourSiteBased.DESCRIPTION,
            questions=[
                RadioButtons(
                    name="location",
                    options=[
                        Option(
                            key="united_kingdom",
                            value=AddSiteForm.WhereIsYourSiteBased.IN_THE_UK,
                            description=AddSiteForm.WhereIsYourSiteBased.
                            IN_THE_UK_DESCRIPTION,
                        ),
                        Option(
                            key="abroad",
                            value=AddSiteForm.WhereIsYourSiteBased.
                            OUTSIDE_THE_UK,
                            description=AddSiteForm.WhereIsYourSiteBased.
                            OUTSIDE_THE_UK_DESCRIPTION,
                        ),
                    ],
                )
            ],
            default_button_name=generic.CONTINUE,
            back_link=BackLink(AddSiteForm.BACK_LINK,
                               reverse_lazy("organisation:sites:sites")),
        ),
        Form(
            caption="Step 2 of 4",
            title=AddSiteForm.Details.TITLE,
            description=AddSiteForm.Details.DESCRIPTION,
            questions=[
                TextInput(title=AddSiteForm.Details.NAME, name="name"),
                Heading(
                    conditional(in_uk, AddSiteForm.Details.ADDRESS_HEADER_UK,
                                AddSiteForm.Details.ADDRESS_HEADER_ABROAD),
                    HeadingStyle.M,
                ),
                *conditional(
                    in_uk,
                    address_questions(None),
                    foreign_address_questions(
                        get_countries(request, True, ["GB"])),
                ),
                HiddenField("validate_only", True),
            ],
            default_button_name=generic.CONTINUE,
        ),
        conditional(
            sites,
            Form(
                title=AddSiteForm.Postcode.TITLE,
                description=AddSiteForm.Postcode.DESCRIPTION.format(", ".join(
                    site["name"] for site in sites)),
                questions=[
                    HiddenField(name="are_you_sure", value=None),
                    RadioButtons(
                        name="are_you_sure",
                        title=AddSiteForm.Postcode.CONTROL_TITLE,
                        options=[
                            Option(True, AddSiteForm.Postcode.YES),
                            Option(False, AddSiteForm.Postcode.NO),
                        ],
                    ),
                ],
                default_button_name=generic.CONTINUE,
            ),
        ),
        site_records_location(request, in_uk),
        Form(
            caption="Step 4 of 4",
            title=AddSiteForm.AssignUsers.TITLE,
            description=AddSiteForm.AssignUsers.DESCRIPTION,
            questions=[
                Filter(placeholder=AddSiteForm.AssignUsers.FILTER),
                Checkboxes(
                    name="users[]",
                    options=get_organisation_users(
                        request,
                        request.user.organisation,
                        {
                            "disable_pagination": True,
                            "exclude_permission": Permissions.ADMINISTER_SITES
                        },
                        True,
                    ),
                    filterable=True,
                ),
                HiddenField("validate_only", False),
            ],
            default_button_name=generic.SAVE_AND_CONTINUE,
        ),
    ])
Exemplo n.º 7
0
def open_general_licence_forms(request, **kwargs):
    open_general_licence_type = OpenGeneralExportLicenceTypes.get_by_acronym(
        kwargs["ogl"])
    control_list_entries = get_control_list_entries(request, True)
    countries = get_countries(request, True)
    selected_entry = request.POST.get("control_list_entry")
    selected_country = next((country.value for country in countries
                             if country.key == request.POST.get("country")),
                            "")
    open_general_licences = get_open_general_licences(
        request,
        convert_to_options=True,
        case_type=open_general_licence_type.id,
        control_list_entry=request.POST.get("control_list_entry"),
        country=request.POST.get("country"),
        status="active",
    )
    sites = get_sites(request, request.user.organisation, True)
    selected_open_general_licence = {}
    if request.POST.get("open_general_licence"):
        selected_open_general_licence = get_open_general_licence(
            request, request.POST.get("open_general_licence"))

    if open_general_licence_type.acronym == OpenGeneralExportLicenceTypes.open_general_export_licence.acronym:
        back_link_url = reverse("apply_for_a_licence:export_licence_questions")
    elif open_general_licence_type.acronym == OpenGeneralExportLicenceTypes.open_general_transhipment_licence.acronym:
        back_link_url = reverse("apply_for_a_licence:transhipment_questions")
    else:
        back_link_url = reverse(
            "apply_for_a_licence:trade_control_licence_questions")

    return FormGroup([
        Form(
            title=OpenGeneralLicenceQuestions.ControlListEntry.TITLE,
            description=OpenGeneralLicenceQuestions.ControlListEntry.
            DESCRIPTION,
            questions=[
                AutocompleteInput(name="control_list_entry",
                                  options=control_list_entries)
            ],
            default_button_name=generic.CONTINUE,
            back_link=BackLink(url=back_link_url),
        ),
        Form(
            title=OpenGeneralLicenceQuestions.Country.TITLE,
            description=OpenGeneralLicenceQuestions.Country.DESCRIPTION,
            questions=[AutocompleteInput(name="country", options=countries)],
            default_button_name=generic.CONTINUE,
        ),
        *conditional(
            open_general_licences,
            [
                Form(
                    title=OpenGeneralLicenceQuestions.OpenGeneralLicences.
                    TITLE.format(open_general_licence_type.name.lower()),
                    questions=[
                        Label(
                            OpenGeneralLicenceQuestions.OpenGeneralLicences.
                            DESCRIPTION.format(
                                open_general_licence_type.name.lower(),
                                selected_entry, selected_country)),
                        Label(OpenGeneralLicenceQuestions.OpenGeneralLicences.
                              HELP_TEXT),
                        RadioButtons(
                            name="open_general_licence",
                            options=[
                                *open_general_licences,
                                Option(
                                    "",
                                    OpenGeneralLicenceQuestions.
                                    OpenGeneralLicences.NONE_OF_THE_ABOVE,
                                    show_or=True,
                                ),
                            ],
                        ),
                    ],
                    default_button_name=generic.CONTINUE,
                )
            ],
            [
                no_open_general_licence_form(open_general_licence_type,
                                             selected_entry, selected_country)
            ],
        ),
        conditional(
            selected_open_general_licence,
            Form(
                caption=conditional(
                    selected_open_general_licence.get("registration_required"),
                    OpenGeneralLicenceQuestions.OpenGeneralLicenceDetail.
                    CAPTION,
                ),
                title=open_general_licence_type.name + " (" +
                selected_open_general_licence.get("name", "") + ")",
                questions=[
                    conditional(
                        not selected_open_general_licence.get(
                            "registration_required"),
                        WarningBanner(
                            "warning",
                            OpenGeneralLicenceQuestions.
                            OpenGeneralLicenceDetail.NO_REGISTRATION_REQUIRED.
                            format(open_general_licence_type.name.lower()),
                        ),
                    ),
                    HiddenField("application_type",
                                open_general_licence_type.acronym.lower()),
                    *conditional(
                        selected_open_general_licence.get(
                            "registration_required"),
                        [
                            Heading(
                                OpenGeneralLicenceQuestions.
                                OpenGeneralLicenceDetail.Summary.HEADING,
                                HeadingStyle.S),
                            Custom(
                                "components/ogl-step-list.html",
                                data={
                                    **selected_open_general_licence, "sites":
                                    sites
                                },
                            ),
                            Custom("components/ogl-warning.html"),
                            Checkboxes(
                                name="confirmation[]",
                                options=[
                                    Option(
                                        "read", OpenGeneralLicenceQuestions.
                                        Conditions.READ),
                                    Option(
                                        "comply", OpenGeneralLicenceQuestions.
                                        Conditions.COMPLY),
                                ],
                            ),
                        ],
                        [],
                    ),
                ],
                buttons=[
                    conditional(
                        selected_open_general_licence.get(
                            "registration_required"),
                        Button("Register", "submit"),
                    )
                ],
            ),
            no_open_general_licence_form(open_general_licence_type,
                                         selected_entry, selected_country),
        ),
    ])
Exemplo n.º 8
0
def select_condition_and_flag(request, type: str):
    flags = []
    is_for_verified_goods_only = None

    if type == "Good":
        flags = get_goods_flags(request=request)
        is_for_verified_goods_only = RadioButtons(
            name="is_for_verified_goods_only",
            options=[
                Option(key=True, value=FlaggingRules.Create.Condition_and_flag.YES_OPTION),
                Option(key=False, value=FlaggingRules.Create.Condition_and_flag.NO_OPTION),
            ],
            title=FlaggingRules.Create.Condition_and_flag.GOODS_QUESTION,
        )
        entries = get_control_list_entries(request)
        clc_groups, clc_nodes = get_clc_entry_groups_and_nodes(entries)

        # if the child node has children of its own then that needs to selectable as
        # both individual entry as well as group entry because of this duplicates are
        # possible in the combined list hence remove them. We need groups at the top
        # because autocomplete only shows first 10 entries which makes it difficult to
        # select certain groups otherwise. eg ML10b1 comes before ML1
        combined_entries = list(clc_groups)
        rating_seen = set([item["rating"] for item in combined_entries])
        for item in clc_nodes:
            if item["rating"] not in rating_seen:
                rating_seen.add(item["rating"])
                combined_entries.append(item)

        clc_nodes_options = [
            Option(key=item["rating"], value=item["rating"], description=item["text"],) for item in clc_nodes
        ]

        clc_groups_options = [
            Option(key=item["rating"], value=item["rating"], description=item["text"],) for item in clc_groups
        ]

        clc_combined_options = [
            Option(key=item["rating"], value=item["rating"], description=item["text"],) for item in combined_entries
        ]

        return Form(
            title="Set flagging rules",
            questions=[
                Heading("Add a condition", HeadingStyle.S),
                TokenBar(
                    title="Select individual control list entries",
                    name="matching_values",
                    description="Type to get suggestions. For example, ML1a.",
                    options=clc_nodes_options,
                ),
                TokenBar(
                    title="Select a control list entry group",
                    name="matching_groups",
                    description="Type to get suggestions. For example, ML8.\nThis will add every control list entry under ML8.",
                    options=clc_groups_options,
                ),
                TokenBar(
                    title="Excluded control list entries",
                    name="excluded_values",
                    description="Type to get suggestions. For example, ML1a, ML8.\nThis will exclude ML1a and every control list entry under ML8.",
                    options=clc_combined_options,
                ),
                Heading("Set an action", HeadingStyle.S),
                Select(title=strings.FlaggingRules.Create.Condition_and_flag.FLAG, name="flag", options=flags),
                is_for_verified_goods_only,
            ],
            default_button_name="Create flagging rule",
        )
    elif type == "Destination":
        flags = get_destination_flags(request=request)

        return Form(
            title="Set flagging rules",
            questions=[
                Heading("Add a condition", HeadingStyle.S),
                TokenBar(
                    title="Select destinations",
                    name="matching_values",
                    description="Type to get suggestions. For example, Australia",
                    options=get_countries(request, convert_to_options=True),
                ),
                Heading("Add an action", HeadingStyle.S),
                Select(title=strings.FlaggingRules.Create.Condition_and_flag.FLAG, name="flag", options=flags),
            ],
            default_button_name="Create flagging rule",
        )
    elif type == "Case":
        case_type_options = [Option(option["key"], option["value"]) for option in get_case_types(request)]
        flags = get_cases_flags(request=request)

        return Form(
            title="Set flagging rules",
            questions=[
                Heading("Add a condition", HeadingStyle.S),
                TokenBar(
                    title="Select application type",
                    name="matching_values",
                    description="Type to get suggestions.\nFor example, Standard Individual Export Licence",
                    options=case_type_options,
                ),
                Heading("Add an action", HeadingStyle.S),
                Select(title=strings.FlaggingRules.Create.Condition_and_flag.FLAG, name="flag", options=flags),
            ],
            default_button_name="Create flagging rule",
        )
Exemplo n.º 9
0
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",
    )
Exemplo n.º 10
0
)
from lite_forms.styles import HeadingStyle
from caseworker.picklists.enums import PicklistCategories


def respond_to_clc_query_form(request, queue_pk, case):
    if case.data["good"]["is_good_controlled"]:
        is_good_controlled = case.data["good"]["is_good_controlled"]["value"]
    else:
        is_good_controlled = None

    return Form(
        title=CLCReviewGoods.TITLE,
        description=CLCReviewGoods.DESCRIPTION,
        questions=[
            Heading(CLCReviewGoods.HEADING, HeadingStyle.S),
            Summary(
                values={
                    CLCReviewGoods.Summary.DESCRIPTION:
                    case.data["good"]["description"],
                    CLCReviewGoods.Summary.PART_NUMBER:
                    default_na(case.data["good"]["part_number"]),
                    CLCReviewGoods.Summary.IS_THIS_GOOD_CONTROLLED:
                    is_good_controlled,
                    CLCReviewGoods.Summary.CONTROL_LIST_ENTRIES:
                    case.data["clc_control_list_entry"],
                    CLCReviewGoods.Summary.EXPLANATION:
                    case.data["clc_raised_reasons"],
                },
                classes=[
                    "govuk-inset-text",