Esempio n. 1
0
 def dispatch(self, request, *args, **kwargs):
     self.object_pk = kwargs["pk"]
     self.application = get_application(request, self.object_pk)
     self.success_url = reverse_lazy("applications:task_list",
                                     kwargs={"pk": self.object_pk
                                             }) + "#end_use_details"
     return super().dispatch(request, *args, **kwargs)
Esempio n. 2
0
 def init(self, request, **kwargs):
     self.object_pk = kwargs["pk"]
     application = get_application(request, self.object_pk)
     self.form = goods_type_form(request, application.sub_type)
     self.action = post_goods_type
     self.success_url = reverse_lazy("applications:goods_types",
                                     kwargs={"pk": self.object_pk})
Esempio n. 3
0
    def init(self, request, **kwargs):
        self.object_pk = kwargs["pk"]
        self.application = get_application(request, self.object_pk)
        has_clearance = self.application["case_type"]["sub_type"][
            "key"] == F680
        clearance_options = get_pv_gradings(
            request, convert_to_options=True) if has_clearance else None

        if self.party_type == "end_user":
            self.forms = self.form(
                request,
                self.application,
                self.strings,
                self.back_url,
                clearance_options=clearance_options,
                is_end_user=True,
            )
        else:
            self.forms = self.form(
                request,
                self.application,
                self.strings,
                self.back_url,
                clearance_options=clearance_options,
            )

        self.data = {"type": self.party_type}
Esempio n. 4
0
    def dispatch(self, request, *args, **kwargs):
        self.application_id = str(kwargs["pk"])
        self.application = get_application(request, self.application_id)
        self.case_id = self.application["case"]
        self.view_type = kwargs.get("type")

        return super(ApplicationDetail, self).dispatch(request, *args, **kwargs)
Esempio n. 5
0
    def get(self, request, **kwargs):
        application_id = str(kwargs["pk"])
        application = get_application(request, application_id)
        is_permanent_app = is_application_export_type_permanent(application)
        if application["end_user"]:
            kwargs = {
                "pk": application_id,
                "obj_pk": application["end_user"]["id"]
            }
            context = {
                "application":
                application,
                "title":
                EndUserPage.TITLE,
                "edit_url":
                reverse("applications:edit_end_user", kwargs=kwargs),
                "remove_url":
                reverse("applications:remove_end_user", kwargs=kwargs),
                "answers":
                convert_party(
                    party=application["end_user"],
                    application=application,
                    editable=application["status"]["value"] == "draft",
                ),
                "highlight": ["Document"] if
                (is_permanent_app and application.sub_type != OPEN
                 and not application["end_user"]["document"]) else {},
            }

            return render(request, "applications/end-user.html", context)
        else:
            return redirect(
                reverse("applications:add_end_user",
                        kwargs={"pk": application_id}))
 def init(self, request, **kwargs):
     self.object_pk = kwargs["pk"]
     self.data = get_application(request, self.object_pk)
     self.form = told_by_an_official_form(self.object_pk)
     self.action = put_application
     self.success_url = reverse_lazy("applications:task_list",
                                     kwargs={"pk": self.object_pk})
Esempio n. 7
0
 def get(self, request, **kwargs):
     application_id = str(kwargs["pk"])
     application = get_application(request, application_id)
     if application["consignee"]:
         kwargs = {
             "pk": application_id,
             "obj_pk": application["consignee"]["id"]
         }
         context = {
             "application":
             application,
             "title":
             ConsigneePage.TITLE,
             "edit_url":
             reverse("applications:edit_consignee", kwargs=kwargs),
             "remove_url":
             reverse("applications:remove_consignee", kwargs=kwargs),
             "answers":
             convert_party(
                 party=application["consignee"],
                 application=application,
                 editable=application["status"]["value"] == "draft",
             ),
         }
         return render(request, "applications/end-user.html", context)
     else:
         return redirect(
             reverse("applications:add_consignee",
                     kwargs={"pk": application_id}))
Esempio n. 8
0
    def get(self, request, **kwargs):
        application_id = str(kwargs["pk"])
        data = get_application(request, application_id)

        if data.get("status") and data.get("status").get("key") == APPLICANT_EDITING:
            return redirect(reverse_lazy("applications:task_list", kwargs={"pk": application_id}))

        return form_page(request, edit_type_form(application_id))
Esempio n. 9
0
    def get(self, request, **kwargs):
        application_id = kwargs["pk"]
        application = get_application(request, application_id)

        context = {
            "application": application,
        }
        return render(request, "applications/submit.html", context)
Esempio n. 10
0
 def init(self, request, **kwargs):
     self.object_pk = kwargs["pk"]
     application = get_application(request, self.object_pk)
     self.data, _ = get_external_locations_on_draft(request, self.object_pk)
     self.form = external_locations_form(request,
                                         application.type_reference)
     self.action = post_external_locations_on_draft
     self.success_url = reverse_lazy("applications:location",
                                     kwargs={"pk": self.object_pk})
Esempio n. 11
0
 def init(self, request, **kwargs):
     self.object_pk = kwargs["pk"]
     application = get_application(request, self.object_pk)
     location_type = request.POST.get("location_type", None)
     self.forms = new_external_location_form(request,
                                             application.type_reference,
                                             location_type)
     self.action = post_external_locations
     self.success_url = reverse_lazy("applications:location",
                                     kwargs={"pk": self.object_pk})
Esempio n. 12
0
 def init(self, request, **kwargs):
     self.object_pk = kwargs["pk"]
     pv_grading_options = get_pv_gradings(request, convert_to_options=True)
     self.form = clearance_level_form(application_id=kwargs["pk"],
                                      options=pv_grading_options)
     self.action = put_application
     self.success_url = reverse_lazy("applications:task_list",
                                     kwargs={"pk": self.object_pk})
     application = get_application(request, self.object_pk)
     self.data = {"clearance_level": application["clearance_level"]}
Esempio n. 13
0
    def get(self, request, **kwargs):
        """
        List of existing goods (add-preexisting)
        """
        application_id = str(kwargs["pk"])
        application = get_application(request, application_id)
        name = request.GET.get("name", "").strip()
        description = request.GET.get("description", "").strip()
        part_number = request.GET.get("part_number", "").strip()
        control_list_entry = request.GET.get("control_list_entry", "").strip()

        filters = FiltersBar([
            TextInput(title="name", name="name"),
            TextInput(title="description", name="description"),
            TextInput(title="control list entry", name="control_list_entry"),
            TextInput(title="part number", name="part_number"),
        ])

        params = {
            "page": int(request.GET.get("page", 1)),
            "name": name,
            "description": description,
            "part_number": part_number,
            "control_list_entry": control_list_entry,
            "for_application": "True",
        }
        goods_list = get_goods(request, **params)

        context = {
            "application":
            application,
            "data":
            goods_list,
            "name":
            name,
            "description":
            description,
            "part_number":
            part_number,
            "control_list_entry":
            control_list_entry,
            "draft_id":
            application_id,
            "params":
            params,
            "page":
            params.pop("page"),
            "params_str":
            convert_dict_to_query_params(params),
            "filters":
            filters,
            "feature_flag_firearms_enabled":
            settings.FEATURE_FLAG_FIREARMS_ENABLED,
        }
        return render(request, "applications/goods/preexisting.html", context)
Esempio n. 14
0
    def on_submission(self, request, **kwargs):
        application = get_application(request, self.object_pk)
        has_clearance = application["case_type"]["sub_type"]["key"] == F680
        if not has_clearance:
            self.forms = self.form(request, application, self.strings,
                                   self.back_url)

        if int(self.request.POST.get("form_pk")) == len(self.forms.forms) - 1:
            self.action = self.post_action
        else:
            self.action = self.validate_action
Esempio n. 15
0
    def get(self, request, **kwargs):
        application_id = str(kwargs["pk"])
        application = get_application(request, application_id)
        ultimate_end_users = get_ultimate_end_users(request, application_id)

        context = {
            "application": application,
            "ultimate_end_users": ultimate_end_users,
        }
        return render(request, "applications/parties/ultimate-end-users.html",
                      context)
Esempio n. 16
0
    def get_form_data(self, request):
        application = get_application(request, self.object_pk)
        data = {}
        if application["is_shipped_waybill_or_lading"] is not None:
            data["is_shipped_waybill_or_lading"] = application[
                "is_shipped_waybill_or_lading"]

        if application["non_waybill_or_lading_route_details"]:
            data["non_waybill_or_lading_route_details"] = application[
                "non_waybill_or_lading_route_details"]

        return data
Esempio n. 17
0
    def get(self, request, **kwargs):
        application_id = str(kwargs["pk"])
        application = get_application(request, application_id)

        context = {
            "application": application,
            "third_parties": application["third_parties"],
            "has_clearance":
            application["case_type"]["sub_type"]["key"] == F680,
        }
        return render(request, "applications/parties/third-parties.html",
                      context)
Esempio n. 18
0
 def init(self, request, **kwargs):
     self.object_pk = str(kwargs["pk"])
     application = get_application(request, self.object_pk)
     self.form = f680_details_form(request, self.object_pk)
     self.action = put_application_with_clearance_types
     self.data = {
         "types": [
             f680_clearance_type["name"]["key"]
             for f680_clearance_type in application["types"]
         ]
     }
     self.success_url = reverse_lazy("applications:task_list",
                                     kwargs={"pk": self.object_pk})
Esempio n. 19
0
    def init(self, request, **kwargs):
        self.object_pk = kwargs["pk"]
        application = get_application(request, self.object_pk)

        if application.status == "submitted" and not application[
                "goods_locations"]["type"] == "sites":
            raise Http404

        self.data, _ = get_sites_on_draft(request, self.object_pk)
        self.form = sites_form(request, application.type_reference)
        self.action = post_sites_on_draft
        self.success_url = reverse_lazy("applications:location",
                                        kwargs={"pk": self.object_pk})
Esempio n. 20
0
    def get(self, request, **kwargs):
        application_id = str(kwargs["pk"])
        application = get_application(request, application_id)
        notes = get_case_notes(request, application_id)["case_notes"]

        context = {
            "application": application,
            "notes": notes,
            "post_url": reverse_lazy("applications:notes", kwargs={"pk": application_id}),
            "error": kwargs.get("error"),
            "text": kwargs.get("text", ""),
        }
        return render(request, "applications/case-notes.html", context)
Esempio n. 21
0
    def dispatch(self, request, *args, **kwargs):
        self.application_id = str(kwargs["pk"])
        self.application = get_application(request, self.application_id)
        self.goods = self.application["goods_types"]
        self.countries = get_application_countries(request,
                                                   self.application_id)

        # Prevent minor edits from accessing this page
        if get_application_edit_type(
                self.application) == ApplicationEditTypes.MINOR_EDIT:
            raise Http404

        return super(GoodsTypeCountries,
                     self).dispatch(request, *args, **kwargs)
 def init(self, request, **kwargs):
     self.success_url = reverse("applications:task_list", kwargs={"pk": kwargs["pk"]}) + "#temporary_export_details"
     self.object_pk = kwargs["pk"]
     application = get_application(request, self.object_pk)
     self.forms = temporary_export_details_form()
     self.action = put_temporary_export_details
     self.data = self._parse_temporary_export_details(application)
     self.summary_list_title = strings.SummaryList.TITLE
     self.summary_list_notice_title = ""
     self.summary_list_notice_text = ""
     self.summary_list_button = generic.SAVE_AND_RETURN
     self.validate_only_until_final_submission = False
     self.cancel_link_text = "cancel"
     self.cancel_link_url = self.success_url
Esempio n. 23
0
    def get(self, request, **kwargs):
        application_id = str(kwargs["pk"])
        application = get_application(request, application_id)

        context = {
            "application_id":
            application_id,
            "goods":
            application["goods"],
            "application_status_draft":
            application["status"]["key"] in ["draft", APPLICANT_EDITING],
        }
        return render(request, "applications/goods/goods-detail-summary.html",
                      context)
Esempio n. 24
0
    def get(self, request, **kwargs):
        """
        Display application submit success page
        This page is accessed one of two ways:
        1. Successful submission of an application
        2. From a bookmark or link - this is intentional as some users will want to
           save the page as evidence
        """
        application_id = kwargs["pk"]
        application = get_application(request, application_id)

        if application.status in ["draft", "applicant_editing"]:
            raise Http404

        return application_success_page(request, application["reference_code"])
Esempio n. 25
0
 def init(self, request, **kwargs):
     self.object_pk = kwargs["pk"]
     application = get_application(request, self.object_pk)
     self.form = confirm_form(
         title=strings.applications.DeleteApplicationPage.TITLE,
         confirmation_name="choice",
         summary=draft_summary(application),
         back_link_text=strings.applications.DeleteApplicationPage.BACK_TEXT,
         yes_label=strings.applications.DeleteApplicationPage.YES_LABEL,
         no_label=strings.applications.DeleteApplicationPage.NO_LABEL,
         submit_button_text=strings.applications.DeleteApplicationPage.SUBMIT_BUTTON,
         back_url=request.GET.get("return_to"),
         side_by_side=True,
     )
     self.action = validate_delete_draft
Esempio n. 26
0
    def post(self, request, **kwargs):
        application_id = str(kwargs["pk"])
        application = get_application(request, str(kwargs["pk"]))

        data, status_code = submit_application(request, application_id)

        if status_code != HTTPStatus.OK:
            return get_application_task_list(request, application, errors=data.get("errors"))

        if application.sub_type not in [NotificationType.EUA, NotificationType.GOODS]:
            # All other application types direct to the summary page
            return HttpResponseRedirect(reverse_lazy("applications:summary", kwargs={"pk": application_id}))
        else:
            # Redirect to the success page to prevent the user going back after the Post
            # Follows this pattern: https://en.wikipedia.org/wiki/Post/Redirect/Get
            return HttpResponseRedirect(reverse_lazy("applications:success_page", kwargs={"pk": application_id}))
Esempio n. 27
0
 def get_context_data(self, **kwargs):
     application = get_application(self.request, kwargs["pk"])
     goods = get_application_goods(self.request, kwargs["pk"])
     includes_firearms = any(
         ["firearm_details" in good.keys() for good in goods])
     is_exhibition = application["case_type"]["sub_type"][
         "key"] == EXHIBITION
     return super().get_context_data(
         goods=goods,
         application=application,
         exhibition=is_exhibition,
         goods_value=None
         if is_exhibition else get_total_goods_value(goods),
         includes_firearms=includes_firearms,
         **kwargs,
     )
Esempio n. 28
0
    def post(self, request, **kwargs):
        draft_id = str(kwargs["pk"])
        application = get_application(request, draft_id)
        is_permanent_application = is_application_export_type_permanent(
            application)
        form = get_upload_page(
            request.path,
            draft_id,
            is_permanent_application=is_permanent_application)

        try:
            files = request.FILES
        except Exception:  # noqa
            return error_page(
                request,
                strings.applications.AttachDocumentPage.UPLOAD_FAILURE_ERROR)

        # Only validate documents if there are any present or are mandatory in the following cases:
        # standard permanent application end user section, additional documents section
        if (files or ("/end-user" in request.path
                      and is_application_export_type_permanent(application))
                or "additional-document" in request.path):
            logging.info(self.request)
            data, error = add_document_data(request)

            if error:
                return form_page(request,
                                 form,
                                 extra_data={"draft_id": draft_id},
                                 errors={"documents": [error]})

            action = document_switch(request.path)["attach"]
            if len(signature(action).parameters) == 3:
                _, status_code = action(request, draft_id, data)
                if status_code == HTTPStatus.CREATED:
                    return get_homepage(request, draft_id)
            else:
                _, status_code = action(request, draft_id, kwargs["obj_pk"],
                                        data)
                if status_code == HTTPStatus.CREATED:
                    return get_homepage(request, draft_id, kwargs["obj_pk"])

            return error_page(
                request,
                strings.applications.AttachDocumentPage.UPLOAD_FAILURE_ERROR)

        return get_homepage(request, draft_id)
Esempio n. 29
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
            },
        )
Esempio n. 30
0
    def init(self, request, **kwargs):
        self.object_pk = kwargs["pk"]
        application = get_application(request, self.object_pk)
        self.form = which_location_form(self.object_pk, application.sub_type)
        self.action = validate_and_update_goods_location_choice
        self.data = {
            "choice":
            Locations.DEPARTED
            if application.get("have_goods_departed") else ""
        }

        if application.status == "submitted":
            if application["goods_locations"]:
                return reverse_lazy("applications:location",
                                    kwargs={"pk": self.object_pk})
            elif application["sites"]:
                return reverse_lazy("applications:existing_sites",
                                    kwargs={"pk": self.object_pk})