Example #1
0
def add_firearm_good_form_group(request,
                                is_pv_graded: bool = None,
                                draft_pk: str = None):
    control_list_entries = get_control_list_entries(request,
                                                    convert_to_options=True)
    return FormGroup([
        add_goods_questions(control_list_entries, draft_pk),
        conditional(is_pv_graded, pv_details_form(request)),
        group_two_product_type_form(),
        firearm_year_of_manufacture_details_form(),
        firearm_calibre_details_form(),
        firearms_act_confirmation_form(),
        identification_markings_form(),
    ])
Example #2
0
def edit_good_detail_form(request, good_id):
    return Form(
        title=EditGoodForm.TITLE,
        description=EditGoodForm.DESCRIPTION,
        questions=[
            TextInput(
                title="Name",
                description=
                ("Give your product a name so it is easier to find in your product list"
                 ),
                name="name",
            ),
            TextArea(
                title=EditGoodForm.Description.TITLE,
                name="description",
                rows=5,
                optional=True,
                extras={"max_length": 280},
            ),
            TextInput(title=EditGoodForm.PartNumber.TITLE,
                      name="part_number",
                      optional=True),
            RadioButtons(
                title=EditGoodForm.IsControlled.TITLE,
                description=EditGoodForm.IsControlled.DESCRIPTION,
                name="is_good_controlled",
                options=[
                    Option(
                        key=True,
                        value=EditGoodForm.IsControlled.YES,
                        components=[
                            control_list_entries_question(
                                control_list_entries=get_control_list_entries(
                                    request, convert_to_options=True),
                                title=EditGoodForm.ControlListEntry.TITLE,
                                description=EditGoodForm.ControlListEntry.
                                DESCRIPTION,
                            ),
                        ],
                    ),
                    Option(key=False, value=EditGoodForm.IsControlled.NO),
                ],
            ),
        ],
        back_link=BackLink(CreateGoodForm.BACK_BUTTON,
                           reverse_lazy("goods:good", kwargs={"pk": good_id})),
    )
Example #3
0
def add_good_form_group(
    request,
    is_pv_graded: bool = None,
    is_software_technology: bool = None,
    is_firearm: bool = None,
    is_firearms_core: bool = None,
    is_firearms_accessory: bool = None,
    is_firearms_software_tech: bool = None,
    draft_pk: str = None,
    base_form_back_link: str = None,
):
    control_list_entries = get_control_list_entries(request,
                                                    convert_to_options=True)
    return FormGroup([
        conditional(not settings.FEATURE_FLAG_ONLY_ALLOW_FIREARMS_PRODUCTS,
                    product_category_form(request)),
        conditional(
            request.POST.get("item_category") == PRODUCT_CATEGORY_FIREARM
            or settings.FEATURE_FLAG_ONLY_ALLOW_FIREARMS_PRODUCTS,
            group_two_product_type_form(back_link=base_form_back_link),
        ),
        conditional(is_firearms_core and draft_pk,
                    identification_markings_form()),
        conditional(is_firearms_core,
                    firearms_sporting_shotgun_form(request.POST.get("type"))),
        add_goods_questions(control_list_entries, draft_pk),
        conditional(is_pv_graded, pv_details_form(request)),
        # only ask if adding to a draft application
        conditional(is_firearm and bool(draft_pk),
                    firearm_year_of_manufacture_details_form()),
        conditional(is_firearm,
                    firearm_replica_form(request.POST.get("type"))),
        conditional(is_firearms_core, firearm_calibre_details_form()),
        conditional(is_firearms_core and bool(draft_pk),
                    firearms_act_confirmation_form()),
        conditional(
            is_firearms_software_tech,
            software_technology_details_form(request,
                                             request.POST.get("type"))),
        conditional(is_firearms_accessory or is_firearms_software_tech,
                    product_military_use_form(request)),
        conditional(is_firearms_accessory, product_component_form(request)),
        conditional(is_firearms_accessory or is_firearms_software_tech,
                    product_uses_information_security(request)),
    ])
Example #4
0
def goods_type_form(request, application_type: str):
    return Form(
        title=CreateGoodsTypeForm.TITLE,
        description=CreateGoodsTypeForm.DESCRIPTION,
        questions=[
            TextArea(title=CreateGoodsTypeForm.Description.TITLE, name="description", extras={"max_length": 2000,}),
            *conditional(
                application_type != HMRC,
                [
                    RadioButtons(
                        title=CreateGoodsTypeForm.IsControlled.TITLE,
                        description=CreateGoodsTypeForm.IsControlled.DESCRIPTION,
                        name="is_good_controlled",
                        options=[
                            Option(
                                key=True,
                                value=CreateGoodsTypeForm.IsControlled.YES,
                                components=[
                                    control_list_entries_question(
                                        control_list_entries=get_control_list_entries(request, convert_to_options=True),
                                    ),
                                ],
                            ),
                            Option(key=False, value=CreateGoodsTypeForm.IsControlled.NO),
                        ],
                    ),
                    RadioButtons(
                        title=CreateGoodsTypeForm.IsIncorporated.TITLE,
                        description=CreateGoodsTypeForm.IsIncorporated.DESCRIPTION,
                        name="is_good_incorporated",
                        options=[
                            Option(key=True, value=CreateGoodsTypeForm.IsIncorporated.YES),
                            Option(key=False, value=CreateGoodsTypeForm.IsIncorporated.NO),
                        ],
                    ),
                ],
                [],
            ),
        ],
    )
Example #5
0
 def control_list(self):
     return get_control_list_entries(self.request, convert_to_options=True)
Example #6
0
def add_good_form_group(
    request,
    application: dict = None,
    is_pv_graded: bool = None,
    is_software_technology: bool = None,
    is_firearm: bool = None,
    is_firearm_ammunition_or_component: bool = None,
    is_firearms_accessory: bool = None,
    is_firearms_software_or_tech: bool = None,
    show_serial_numbers_form: bool = False,
    draft_pk: str = None,
    base_form_back_link: str = None,
    is_rfd: bool = False,
):
    application = application or {}

    control_list_entries = get_control_list_entries(request, convert_to_options=True)
    is_category_firearms = (
        request.POST.get("item_category") == PRODUCT_CATEGORY_FIREARM
        or settings.FEATURE_FLAG_ONLY_ALLOW_FIREARMS_PRODUCTS
    )

    show_attach_rfd = str_to_bool(request.POST.get("is_registered_firearm_dealer"))
    is_preexisting = str_to_bool(request.GET.get("preexisting", False))
    # when adding to product list then always show RFD question if not yet have a valid RFD certificate
    # when adding to application then show RFD question if has expired RFD and not show if they do not have one yet
    if is_preexisting:
        show_rfd_question = is_firearm_ammunition_or_component and has_expired_rfd_certificate(application)
    else:
        show_rfd_question = is_firearm_ammunition_or_component and not has_valid_rfd_certificate(application)

    return FormGroup(
        [
            conditional(not settings.FEATURE_FLAG_ONLY_ALLOW_FIREARMS_PRODUCTS, product_category_form(request)),
            conditional(is_category_firearms, group_two_product_type_form(back_link=base_form_back_link),),
            conditional(is_firearm_ammunition_or_component, firearms_sporting_shotgun_form(request.POST.get("type"))),
            conditional(
                is_firearm_ammunition_or_component and draft_pk, firearms_number_of_items(request.POST.get("type"))
            ),
            conditional(is_firearm_ammunition_or_component and draft_pk, identification_markings_form()),
            conditional(
                is_firearm_ammunition_or_component and draft_pk and show_serial_numbers_form,
                firearms_capture_serial_numbers(request.POST.get("number_of_items", 0)),
            ),
            conditional(not is_category_firearms, product_military_use_form(request)),
            conditional(not is_category_firearms, product_uses_information_security(request)),
            add_goods_questions(control_list_entries, draft_pk),
            conditional(is_pv_graded, pv_details_form(request)),
            # only ask if adding to a draft application
            conditional(is_firearm and bool(draft_pk), firearm_year_of_manufacture_details_form()),
            conditional(is_firearm, firearm_replica_form(request.POST.get("type"))),
            conditional(is_firearm_ammunition_or_component, firearm_calibre_details_form()),
            conditional(show_rfd_question, is_registered_firearm_dealer_field(base_form_back_link)),
            conditional(show_attach_rfd, attach_firearm_dealer_certificate_form(base_form_back_link)),
            conditional(is_firearm_ammunition_or_component and bool(draft_pk), firearms_act_confirmation_form(is_rfd)),
            conditional(
                is_firearms_software_or_tech, software_technology_details_form(request, request.POST.get("type"))
            ),
            conditional(is_firearms_accessory or is_firearms_software_or_tech, product_military_use_form(request)),
            conditional(is_firearms_accessory, product_component_form(request)),
            conditional(
                is_firearms_accessory or is_firearms_software_or_tech, product_uses_information_security(request)
            ),
        ]
    )
Example #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.session["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),
        ),
    ])