Пример #1
0
    def post(self, request, **kwargs):
        draft_pk = str(kwargs.get("draft_pk", ""))
        good_id = str(kwargs["pk"])
        back_link = BackLink(
            AttachDocumentForm.BACK_FORM_LINK, reverse("goods:check_document_sensitivity", kwargs={"pk": good_id}),
        )

        data, error = add_document_data(request)
        if error:
            form = attach_documents_form(back_link)
            return form_page(request, form, errors={"file": ["Select a document"]})

        data, status_code = post_good_documents(request, good_id, data)
        if status_code != HTTPStatus.CREATED:
            return error_page(request, data["errors"]["file"])

        if draft_pk:
            return redirect(
                reverse(
                    "goods:good_detail_application",
                    kwargs={"pk": good_id, "type": "application", "draft_pk": draft_pk},
                )
            )
        else:
            return redirect(reverse("goods:good", kwargs={"pk": good_id}))
Пример #2
0
    def post(self, request, **kwargs):
        good_id = str(kwargs["good_pk"])
        draft_id = str(kwargs["pk"])
        back_link = BackLink(
            "Back",
            reverse("applications:document_grading",
                    kwargs={
                        "pk": draft_id,
                        "good_pk": good_id
                    }))

        data, error = add_document_data(request)
        if error:
            form = attach_documents_form(back_link)
            return form_page(request,
                             form,
                             errors={"file": ["Select a document"]})

        data, status_code = post_good_documents(request, good_id, data)
        if status_code != HTTPStatus.CREATED:
            return error_page(request, data["errors"]["file"])

        return redirect(
            reverse_lazy("applications:add_good_to_application",
                         kwargs={
                             "pk": draft_id,
                             "good_pk": good_id
                         }) +
            f"?preexisting={self.request.GET.get('preexisting', False)}")
Пример #3
0
    def post(self, request, **kwargs):
        data, error = add_document_data(request)
        if error:
            return error_page(request, error)

        data, status_code = post_ecju_query_document(request, self.case_pk,
                                                     self.query_pk, data)
        if status_code != HTTPStatus.CREATED:
            return error_page(request, data["errors"]["file"])

        return redirect(self.success_url)
Пример #4
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)
Пример #5
0
    def post(self, request, **kwargs):
        self.request.upload_handlers.insert(0, S3FileUploadHandler(request))

        good_id = str(kwargs["pk"])
        draft_pk = str(kwargs.get("draft_pk", ""))
        good, _ = get_good(request, good_id)

        data, error = add_document_data(request)

        if error:
            return error_page(request, error)

        data, status_code = post_good_documents(request, good_id, data)
        if status_code != HTTPStatus.CREATED:
            return error_page(request, data["errors"]["file"])

        raise_a_clc_query = good["is_good_controlled"] is None
        raise_a_pv_query = "grading_required" == good["is_pv_graded"]["key"]

        if draft_pk:
            if not (raise_a_clc_query or raise_a_pv_query):
                return redirect(
                    reverse(
                        "goods:good_detail_application",
                        kwargs={
                            "pk": good_id,
                            "type": "application",
                            "draft_pk": draft_pk
                        },
                    ))
            else:
                return redirect(
                    reverse("goods:raise_goods_query_add_application",
                            kwargs={
                                "pk": good_id,
                                "draft_pk": draft_pk
                            }))
        else:
            if not (raise_a_clc_query or raise_a_pv_query):
                return redirect(reverse("goods:good", kwargs={"pk": good_id}))
            else:
                return redirect(
                    reverse("goods:raise_goods_query", kwargs={"pk": good_id}))
Пример #6
0
    def post(self, request, **kwargs):
        self.request.upload_handlers.insert(0, S3FileUploadHandler(request))

        good_id = str(kwargs["good_pk"])
        draft_id = str(kwargs["pk"])
        data, error = add_document_data(request)

        if error:
            return error_page(request, error)

        data, status_code = post_good_documents(request, good_id, data)
        if status_code != HTTPStatus.CREATED:
            return error_page(request, data["errors"]["file"])

        return redirect(
            reverse_lazy("applications:add_good_to_application",
                         kwargs={
                             "pk": draft_id,
                             "good_pk": good_id
                         }) +
            f"?preexisting={self.request.GET.get('preexisting', False)}")
Пример #7
0
    def post(self, request, **kwargs):
        self.request.upload_handlers.insert(0, S3FileUploadHandler(request))
        certificate_available = request.POST.get("section_certificate_missing",
                                                 False) is False

        doc_data = {}
        doc_error = None
        new_file_selected = False
        file_upload_key = f"{self.firearms_data_id}_file"

        doc_data, doc_error = add_document_data(request)
        if doc_data:
            request.session[file_upload_key] = doc_data
            self.certificate_filename = doc_data["name"]
            new_file_selected = True
        else:
            file_info = request.session.get(file_upload_key)
            if file_info:
                doc_data = file_info
                doc_error = None
                new_file_selected = True
                self.certificate_filename = file_info["name"]

        old_post = request.session.get(self.firearms_data_id, None)
        if not old_post:
            return error_page(
                request,
                "Firearms data from previous forms is missing in session")

        copied_request = {k: request.POST.get(k) for k in request.POST}
        data = {**old_post, **copied_request}
        back_link = build_firearm_back_link_create(
            form_url=reverse("applications:new_good",
                             kwargs={"pk": kwargs["pk"]}),
            form_data=old_post,
        )

        if self.good_pk:
            response, status_code = post_good_on_application(
                request, self.draft_pk, data)
            if status_code != HTTPStatus.CREATED:
                if doc_error:
                    response["errors"]["file"] = [
                        "Select certificate file to upload"
                    ]
                form = upload_firearms_act_certificate_form(
                    section="section",
                    filename=self.certificate_filename,
                    back_link=back_link,
                )
                return form_page(request,
                                 form,
                                 data=data,
                                 errors=response["errors"])

            success_url = reverse_lazy("applications:goods",
                                       kwargs={"pk": self.draft_pk})

        else:
            response, status_code = post_goods(request, data)
            if status_code != HTTPStatus.CREATED:
                if doc_error:
                    response["errors"]["file"] = [
                        "Select certificate file to upload"
                    ]
                form = upload_firearms_act_certificate_form(
                    section="section",
                    filename=self.certificate_filename,
                    back_link=back_link,
                )
                return form_page(request,
                                 form,
                                 data=data,
                                 errors=response["errors"])

            self.good_pk = response["good"]["id"]
            success_url = reverse("applications:add_good_summary",
                                  kwargs={
                                      "pk": self.draft_pk,
                                      "good_pk": self.good_pk
                                  })

        if certificate_available and new_file_selected:
            data, status_code = post_application_document(
                request, self.draft_pk, self.good_pk, doc_data)
            if status_code != HTTPStatus.CREATED:
                return error_page(request, data["errors"]["file"])
        elif doc_data:
            delete_application_document_data(request, self.draft_pk,
                                             self.good_pk, doc_data)

        self.certificate_filename = ""
        del request.session[self.firearms_data_id]
        del request.session[file_upload_key]
        request.session.modified = True

        return redirect(success_url)
Пример #8
0
    def post(self, request, **kwargs):
        self.request.upload_handlers.insert(0, S3FileUploadHandler(request))
        self.init(request, **kwargs)
        doc_data = {}
        new_file_selected = False
        file_upload_key = f"{self.firearms_data_id}_file"

        json = {k: v for k, v in request.POST.items()}
        certificate_available = json.get("section_certificate_missing",
                                         False) is False

        doc_data, _ = add_document_data(request)
        if doc_data:
            self.request.session[file_upload_key] = doc_data
            self.certificate_filename = doc_data["name"]
            new_file_selected = True
        else:
            file_info = self.request.session.get(file_upload_key)
            if file_info:
                doc_data = file_info
                new_file_selected = True
                self.certificate_filename = file_info["name"]

        # if certificate_available and error and self.certificate_filename == "":
        if certificate_available and self.certificate_filename == "":
            form = upload_firearms_act_certificate_form(
                self.selected_section, self.certificate_filename,
                self.back_link)
            return form_page(
                request,
                form,
                data=json,
                errors={"file": ["Select certificate file to upload"]})

        validated_data, _ = edit_good_firearm_details(request,
                                                      kwargs["good_pk"], json)
        if "errors" in validated_data:
            form = upload_firearms_act_certificate_form(
                self.selected_section, self.certificate_filename,
                self.back_link)
            return form_page(request,
                             form,
                             data=json,
                             errors=validated_data["errors"])

        if certificate_available and new_file_selected:
            fetch_and_delete_previous_application_documents(
                request, kwargs["pk"], kwargs["good_pk"])

            data, status_code = post_application_document(
                request, kwargs["pk"], kwargs["good_pk"], doc_data)
            if status_code != HTTPStatus.CREATED:
                return error_page(request, data["errors"]["file"])

        if not certificate_available and self.certificate_filename:
            fetch_and_delete_previous_application_documents(
                request, kwargs["pk"], kwargs["good_pk"])

        if file_upload_key in request.session.keys():
            del self.request.session[file_upload_key]
            self.request.session.modified = True

        return redirect(
            reverse("applications:add_good_summary",
                    kwargs={
                        "pk": kwargs["pk"],
                        "good_pk": kwargs["good_pk"]
                    }))
Пример #9
0
    def post(self, request, **kwargs):
        self.init(request, **kwargs)
        doc_data = {}
        new_file_selected = False
        file_upload_key = f"{self.firearms_data_id}_file"

        json = {k: v for k, v in request.POST.items()}
        certificate_available = json.get("section_certificate_missing", False) is False

        doc_data, _ = add_document_data(request)
        if doc_data:
            self.request.session[file_upload_key] = doc_data
            self.certificate_filename = doc_data["name"]
            new_file_selected = True
        else:
            file_info = self.request.session.get(file_upload_key)
            if file_info:
                doc_data = file_info
                new_file_selected = True
                self.certificate_filename = file_info["name"]

        # if certificate_available and error and self.certificate_filename == "":
        if certificate_available and self.certificate_filename == "":
            form = upload_firearms_act_certificate_form(
                self.selected_section, self.certificate_filename, self.back_link
            )
            return form_page(request, form, data=json, errors={"file": ["Select certificate file to upload"]})

        validated_data, _ = edit_good_firearm_details(request, kwargs["good_pk"], json)
        if "errors" in validated_data:
            form = upload_firearms_act_certificate_form(
                self.selected_section, self.certificate_filename, self.back_link
            )
            return form_page(request, form, data=json, errors=validated_data["errors"])

        if certificate_available and new_file_selected:
            fetch_and_delete_previous_application_documents(request, kwargs["pk"], kwargs["good_pk"])

            document_types = {
                "Section 1": "section-one-certificate",
                "Section 2": "section-two-certificate",
                "Section 5": "section-five-certificate",
            }

            doc_data["document_on_organisation"] = {
                "expiry_date": format_date(request.POST, "section_certificate_date_of_expiry"),
                "reference_code": request.POST["section_certificate_number"],
                "document_type": document_types[self.selected_section],
            }

            data, status_code = post_application_document(request, kwargs["pk"], kwargs["good_pk"], doc_data)
            if status_code != HTTPStatus.CREATED:
                return error_page(request, data["errors"]["file"])

        if not certificate_available and self.certificate_filename:
            fetch_and_delete_previous_application_documents(request, kwargs["pk"], kwargs["good_pk"])

        if file_upload_key in request.session.keys():
            del self.request.session[file_upload_key]
            self.request.session.modified = True

        return redirect(
            reverse("applications:add_good_summary", kwargs={"pk": kwargs["pk"], "good_pk": kwargs["good_pk"]})
        )
Пример #10
0
    def post(self, request, **kwargs):
        certificate_available = request.POST.get("section_certificate_missing",
                                                 False) is False

        doc_data = {}
        doc_error = None
        new_file_selected = False
        file_upload_key = f"{self.firearms_data_id}_file"

        doc_data, doc_error = add_document_data(request)
        if doc_data:
            request.session[file_upload_key] = doc_data
            self.certificate_filename = doc_data["name"]
            new_file_selected = True
        else:
            file_info = request.session.get(file_upload_key)
            if file_info:
                doc_data = file_info
                doc_error = None
                new_file_selected = True
                self.certificate_filename = file_info["name"]

        old_post = request.session.get(self.firearms_data_id, None)
        if not old_post:
            return error_page(
                request,
                "Firearms data from previous forms is missing in session")

        copied_request = {k: request.POST.get(k) for k in request.POST}
        data = {**old_post, **copied_request}
        back_link = build_firearm_back_link_create(
            form_url=reverse("applications:new_good",
                             kwargs={"pk": kwargs["pk"]}),
            form_data=old_post,
        )

        errors = validate_expiry_date(request,
                                      "section_certificate_date_of_expiry")
        if errors:
            form = upload_firearms_act_certificate_form(
                section="section",
                filename=self.certificate_filename,
                back_link=back_link,
            )
            return form_page(
                request,
                form,
                data=data,
                errors={"section_certificate_date_of_expiry": errors})

        if self.good_pk:
            response, status_code = post_good_on_application(
                request, self.draft_pk, data)
            if status_code != HTTPStatus.CREATED:
                if doc_error:
                    response["errors"]["file"] = [
                        "Select certificate file to upload"
                    ]
                form = upload_firearms_act_certificate_form(
                    section="section",
                    filename=self.certificate_filename,
                    back_link=back_link,
                )
                return form_page(request,
                                 form,
                                 data=data,
                                 errors=response["errors"])

            success_url = reverse_lazy("applications:goods",
                                       kwargs={"pk": self.draft_pk})

        else:
            response, status_code = post_goods(request, data)
            if status_code != HTTPStatus.CREATED:
                if doc_error:
                    response["errors"]["file"] = [
                        "Select certificate file to upload"
                    ]
                form = upload_firearms_act_certificate_form(
                    section="section",
                    filename=self.certificate_filename,
                    back_link=back_link,
                )
                return form_page(request,
                                 form,
                                 data=data,
                                 errors=response["errors"])

            self.good_pk = response["good"]["id"]
            success_url = reverse("applications:add_good_summary",
                                  kwargs={
                                      "pk": self.draft_pk,
                                      "good_pk": self.good_pk
                                  })

        if certificate_available and new_file_selected:
            document_types = {
                "Section 1": "section-one-certificate",
                "Section 2": "section-two-certificate",
                "Section 5": "section-five-certificate",
            }
            doc_data["document_on_organisation"] = {
                "expiry_date":
                format_date(request.POST,
                            "section_certificate_date_of_expiry"),
                "reference_code":
                request.POST["section_certificate_number"],
                "document_type":
                document_types[self.selected_section],
            }
            data, status_code = post_application_document(
                request, self.draft_pk, self.good_pk, doc_data)
            if status_code != HTTPStatus.CREATED:
                return error_page(request, data["errors"]["file"])
        elif doc_data:
            delete_application_document_data(request, self.draft_pk,
                                             self.good_pk, doc_data)

        self.certificate_filename = ""
        del request.session[self.firearms_data_id]
        request.session.pop(file_upload_key, None)
        request.session.modified = True

        return redirect(success_url)