Exemplo n.º 1
0
def post_good_on_application(request, pk, json):
    good = None
    preexisting = str_to_bool(request.GET.get("preexisting"))
    if json.get("good_id"):
        good, _ = services.get_good(request, json["good_id"])
    post_data = serialize_good_on_app_data(json, good, preexisting)
    response = client.post(request, f"/applications/{pk}/goods/", post_data)
    return response.json(), response.status_code
Exemplo n.º 2
0
    def init(self, request, **kwargs):
        self.object_pk = kwargs["pk"]
        self.good_pk = kwargs["good_pk"]
        self.application = get_application(self.request, self.object_pk)

        self.sub_case_type = self.application["case_type"]["sub_type"]
        is_preexisting = str_to_bool(request.GET.get("preexisting", True))
        show_attach_rfd = str_to_bool(
            request.POST.get("is_registered_firearm_dealer"))
        is_rfd = show_attach_rfd or has_valid_rfd_certificate(self.application)
        firearm_product_type = self.good["firearm_details"]["type"]["key"]
        (
            is_firearm,
            is_firearm_ammunition_or_component,
            is_firearms_accessory,
            is_firearms_software_or_tech,
        ) = get_firearms_subcategory(firearm_product_type)

        self.forms = good_on_application_form_group(
            request=request,
            is_preexisting=is_preexisting,
            good=self.good,
            sub_case_type=self.sub_case_type,
            draft_pk=self.object_pk,
            application=self.application,
            show_attach_rfd=show_attach_rfd,
            relevant_firearm_act_section=request.POST.get(
                "firearm_act_product_is_coverd_by"),
            is_firearm=is_firearm,
            is_firearm_ammunition_or_component=
            is_firearm_ammunition_or_component,
            is_firearms_accessory=is_firearms_accessory,
            is_firearms_software_or_tech=is_firearms_software_or_tech,
            back_url=reverse("applications:preexisting_good",
                             kwargs={"pk": self.object_pk}),
            show_serial_numbers_form=True,
            is_rfd=is_rfd,
        )
        self._action = validate_good_on_application
        self.success_url = reverse_lazy(
            "applications:attach-firearms-certificate-existing-good",
            kwargs={
                "pk": self.object_pk,
                "good_pk": self.good_pk
            },
        )
Exemplo n.º 3
0
    def get(self, request, **kwargs):
        params = {"page": int(request.GET.get("page", 1)), "submitted": str_to_bool(request.GET.get("submitted", True))}
        organisation = get_organisation(request, request.session["organisation"])
        applications = get_applications(request, **params)

        context = {
            "applications": applications,
            "organisation": organisation,
            "params": params,
            "page": params.pop("page"),
            "params_str": convert_dict_to_query_params(params),
        }
        return render(
            request, "applications/applications.html" if params["submitted"] else "applications/drafts.html", context
        )
Exemplo n.º 4
0
def questions_action(request, pk, data):
    if str_to_bool(data.get("expedited", False)):
        if "year" in data and "month" in data and "day" in data:
            data[
                "expedited_date"] = f"{data['year']}-{str(data['month']).zfill(2)}-{str(data['day']).zfill(2)}"

    else:
        if "expedited_date" in data:
            del data["expedited_date"]
    empty_keys = []
    for key in data:
        try:
            # Try to cast to dict if str in order to handle key|value pairs
            data[key] = json.loads(data[key])
            if isinstance(data[key], dict) and "key" in data[key]:
                data[key] = data[key]["key"]
        except (TypeError, ValueError, SyntaxError):
            pass
        if not isinstance(data[key], bool) and not data[key]:
            empty_keys.append(key)

    return put_application(request, pk, data)
Exemplo n.º 5
0
    def init(self, request, **kwargs):
        self.object_pk = kwargs["pk"]
        self.good_pk = kwargs["good_pk"]
        application = get_application(self.request, self.object_pk)
        good, _ = get_good(request, self.good_pk)

        sub_case_type = application["case_type"]["sub_type"]
        is_preexisting = str_to_bool(request.GET.get("preexisting", True))

        self.forms = good_on_application_form_group(
            request,
            is_preexisting=is_preexisting,
            good=good,
            sub_case_type=sub_case_type,
            draft_pk=self.object_pk)

        self.action = validate_good_on_application
        self.success_url = reverse_lazy(
            "applications:attach-firearms-certificate-existing-good",
            kwargs={
                "pk": self.object_pk,
                "good_pk": self.good_pk
            },
        )
Exemplo n.º 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)
            ),
        ]
    )
Exemplo n.º 7
0
 def on_submission(self, request, **kwargs):
     # Take the user out of the journey if they say no to continuing with a site
     # that has a postcode which already exists
     if request.POST.get("are_you_sure") != "None" and str_to_bool(
             request.POST.get("are_you_sure", True)) is False:
         return reverse("organisation:sites:sites")
Exemplo n.º 8
0
    def on_submission(self, request, **kwargs):
        is_preexisting = str_to_bool(request.GET.get("preexisting", True))
        copied_request = request.POST.copy()
        show_attach_rfd = str_to_bool(
            copied_request.get("is_registered_firearm_dealer"))
        relevant_firearm_act_section = copied_request.get(
            "firearm_act_product_is_coverd_by")
        back_url = reverse("applications:preexisting_good",
                           kwargs={"pk": self.good_pk})

        number_of_items = copied_request.get("number_of_items")
        if self.good.get("firearm_details"):
            self.good["firearm_details"]["number_of_items"] = number_of_items

        is_rfd = show_attach_rfd or has_valid_rfd_certificate(self.application)
        selected_section = copied_request.get("firearms_act_section")
        if is_rfd and copied_request.get(
                "is_covered_by_firearm_act_section_one_two_or_five") == "Yes":
            selected_section = "firearms_act_section5"

        show_section_upload_form = False
        if copied_request.get(
                "is_covered_by_firearm_act_section_one_two_or_five") == "Yes":
            show_section_upload_form = is_firearm_certificate_needed(
                application=self.application,
                selected_section=selected_section)

        show_serial_numbers_form = True
        if copied_request.get("has_identification_markings") == "False":
            show_serial_numbers_form = False

        (
            is_firearm,
            is_firearm_ammunition_or_component,
            is_firearms_accessory,
            is_firearms_software_or_tech,
        ) = get_firearms_subcategory(copied_request.get("type"))

        self.forms = good_on_application_form_group(
            request,
            is_preexisting,
            self.good,
            self.sub_case_type,
            self.object_pk,
            self.application,
            show_attach_rfd,
            relevant_firearm_act_section,
            is_firearm=is_firearm,
            is_firearm_ammunition_or_component=
            is_firearm_ammunition_or_component,
            is_firearms_accessory=is_firearms_accessory,
            is_firearms_software_or_tech=is_firearms_software_or_tech,
            back_url=back_url,
            show_serial_numbers_form=show_serial_numbers_form,
            is_rfd=is_rfd,
        )

        # we require the form index of the last form in the group, not the total number
        if self.form_pk == self.number_of_forms:
            if show_section_upload_form:
                firearms_data_id = f"post_{request.session['lite_api_user_id']}_{self.object_pk}_{self.good_pk}"

                session_data = self.request.POST.copy().dict()
                if "firearms_act_section" not in session_data:
                    session_data["firearms_act_section"] = selected_section

                request.session[firearms_data_id] = session_data
            else:
                self._action = post_good_on_application
                self.success_url = reverse("applications:goods",
                                           kwargs={"pk": self.object_pk})

            # if firearm section 5 is selected and the organization already has a valid section 5 then use saved details
            details = self.good["firearm_details"]
            section = None
            if details:
                section = self.request.POST.get(
                    "firearms_act_section") or details["firearms_act_section"]

            if not is_firearm_certificate_needed(application=self.application,
                                                 selected_section=section):
                if section == "firearms_act_section5":
                    document = self.get_section_document()
                    expiry_date = datetime.strptime(document["expiry_date"],
                                                    "%d %B %Y")
                    self.request.POST = self.request.POST.copy()
                    self.request.POST.update({
                        "section_certificate_missing":
                        details["section_certificate_missing"],
                        "section_certificate_missing_reason":
                        details["section_certificate_missing_reason"],
                        "section_certificate_number":
                        document["reference_code"],
                        "section_certificate_date_of_expiryday":
                        expiry_date.strftime("%d"),
                        "section_certificate_date_of_expirymonth":
                        expiry_date.strftime("%m"),
                        "section_certificate_date_of_expiryyear":
                        expiry_date.strftime("%Y"),
                        "firearms_certificate_uploaded":
                        bool(
                            details.get("section_certificate_missing_reason")),
                    })