def post_compliance_person_present(request, case_id, json): data = client.post(request, f"/compliance/visit/{case_id}/people-present/", data=json) # Translate errors to be more user friendly, from # {'errors': [{}, {'name': ['This field may not be blank.'], 'job_title': ['This field may not be blank.']}, ...]} # to # {'errors': {'name-2': ['This field may not be blank'], 'job-title-2': ['This field may not be blank'], ...}} # This allows the errors to specify the specific textbox input for name/job-title inputs allowing the users # to see the exact field it didn't validate on. if "errors" in data.json(): errors = data.json()["errors"] translated_errors = {} index = 1 for error in errors: if error: if "name" in error: translated_errors[f"name-{index}"] = [ f"{index}. " + error.pop("name")[0] ] if "job_title" in error: translated_errors[f"job-title-{index}"] = [ f"{index}. " + error.pop("job_title")[0] ] index += 1 return {**json, "errors": translated_errors}, data.status_code return data.json(), data.status_code
def post(self, request, **kwargs): data = [] for match_id in request.POST.getlist("objects", []): data.append({"application": str(kwargs["pk"]), "denial": match_id, "category": kwargs["category"]}) response = client.post(request, f"/applications/{kwargs['pk']}/denial-matches/", data) response.raise_for_status() return redirect(reverse("cases:case", kwargs={"queue_pk": kwargs["queue_pk"], "pk": kwargs["pk"]}))
def post_enforcement_xml(request, queue_pk, json): if len(request.FILES) == 0: return { "errors": { "file": [UploadEnforcementXML.Errors.NO_FILE] } }, HTTPStatus.BAD_REQUEST if len(request.FILES) != 1: return { "errors": { "file": [UploadEnforcementXML.Errors.MULTIPLE_FILES] } }, HTTPStatus.BAD_REQUEST if request.FILES["file"].size > ENFORCEMENT_XML_MAX_FILE_SIZE: return { "errors": { "file": [UploadEnforcementXML.Errors.FILE_TOO_LARGE] } }, HTTPStatus.BAD_REQUEST try: file = request.FILES.pop("file")[0] file_format = {"file": file.read().decode("utf-8")} except Exception: # noqa return { "errors": { "file": [UploadEnforcementXML.Errors.FILE_READ] } }, HTTPStatus.BAD_REQUEST data = client.post(request, f"/cases/enforcement-check/{queue_pk}", file_format) return data.json(), data.status_code
def post_good_documents(request, pk, json): if "description" not in json: json["description"] = "" json = [json] data = client.post(request, f"/goods/{pk}/documents/", json) return data.json(), data.status_code
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
def _register_organisation(request, json, _type): data = { "type": _type, "user": { "email": request.session["email"] }, } response = client.post(request, "/organisations/", {**json, **data}) return response.json(), response.status_code
def post_review_goods(request, case_id, json): json = { "objects": request.GET.getlist("goods", request.GET.getlist("goods_types")), "comment": request.POST.get("comment"), "control_list_entries": request.POST.getlist("control_list_entries[]", []), "is_good_controlled": request.POST.get("is_good_controlled") == "True", "report_summary": request.POST.get("report_summary"), } response = client.post(request, f"/goods/control-list-entries/{case_id}/", json) return response.json(), response.status_code
def post_sites(request, organisation_id, json): if json.get("are_you_sure", True) == "None": return ( {"errors": {"are_you_sure": [AddSiteForm.WhereIsYourSiteBased.EXISTING_SITE_ERROR]}}, HTTPStatus.BAD_REQUEST, ) if "location" not in json: return {"errors": {"location": [AddSiteForm.WhereIsYourSiteBased.ERROR]}}, HTTPStatus.BAD_REQUEST data = client.post(request, f"/organisations/{organisation_id}/sites/", json) return data.json(), data.status_code
def post_external_locations(request, pk, json): organisation_id = request.session["organisation"] data = client.post( request, f"/organisations/{organisation_id}/external_locations/", json) if "errors" in data.json(): return data.json(), data.status_code # Append the new external location to the list of external locations rather than clearing them _id = data.json()["external_location"]["id"] data = {"external_locations": [_id], "method": "append_location"} return post_external_locations_on_draft(request, str(pk), data)
def post_organisations(request, json): errors = {} if not json.get("type"): errors["type"] = [RegisterAnOrganisation.CommercialOrIndividual.ERROR] if not json.get("location"): errors["location"] = [ RegisterAnOrganisation.WhereIsTheExporterBased.ERROR ] if errors: return {"errors": errors}, HTTPStatus.BAD_REQUEST data = client.post(request, "/organisations/", json) return data.json(), data.status_code
def post_open_licence_return(request, json): if not json.get("year"): return { "errors": { "year": [OpenReturnsForm.Year.ERROR] } }, HTTPStatus.BAD_REQUEST if len(request.FILES) == 0: return { "errors": { "file": [OpenReturnsForm.Upload.NO_FILE_ERROR] } }, HTTPStatus.BAD_REQUEST if len(request.FILES) != 1: return { "errors": { "file": [OpenReturnsForm.Upload.MULTIPLE_FILES_ERROR] } }, HTTPStatus.BAD_REQUEST if request.FILES[ "file"].size > constants.MAX_OPEN_LICENCE_RETURNS_FILE_SIZE: return { "errors": { "file": [OpenReturnsForm.Upload.SIZE_ERROR] } }, HTTPStatus.BAD_REQUEST try: file = request.FILES.pop("file")[0] json["file"] = file.read().decode("utf-8") except Exception: # noqa return { "errors": { "file": [OpenReturnsForm.Upload.READ_ERROR] } }, HTTPStatus.BAD_REQUEST data = client.post(request, "/compliance/open-licence-returns/", json) return data.json(), data.status_code
def post_goods(request, json): json["item_category"] = json.get("item_category", "group2_firearms") if "is_pv_graded" in json and json["is_pv_graded"] == "yes": if "reference" in json: json["pv_grading_details"] = { "grading": json["grading"], "custom_grading": json["custom_grading"], "prefix": json["prefix"], "suffix": json["suffix"], "issuing_authority": json["issuing_authority"], "reference": json["reference"], "date_of_issue": format_date(json, "date_of_issue"), } if "item_category" in json and json["item_category"] == "group2_firearms": add_firearm_details_to_data(json) data = client.post(request, "/goods/", json) if data.status_code == HTTPStatus.OK: data.json().get("good"), data.status_code return data.json(), data.status_code
def post_picklist_item(request, json): data = client.post(request, "/picklist/", json) return data.json(), data.status_code
def post_letter_template(request, json): data = client.post(request, "/letter-templates/", json) return data.json(), data.status_code
def raise_goods_query(request, pk, json): post_data = json post_data["good_id"] = pk data = client.post(request, "/queries/goods-queries/", post_data) return data.json(), data.status_code
def post_routing_rule(request, json): data = _remove_none_from_post_data_additional_rules_list(json) data = convert_flags_to_list(data) response = client.post(request, "/routing-rules/", data) return response.json(), response.status_code
def create_spire_product_comment(request, pk, data): response = client.post(request, f"/search/product/spire/{pk}/comment/", data) response.raise_for_status() return response.json()
def post_role(request, json): data = client.post(request, "/gov-users/roles/", json) return data.json(), data.status_code
def upload_denials(request, data): return client.post( request=request, appended_address="/external-data/denial/", data=data, )
def post_good_document_sensitivity(request, pk, json): data = client.post(request, f"/goods/{pk}/document-sensitivity/", json) return data.json(), data.status_code
def post_open_general_licence_cases(request, json): data = client.post(request, "/licences/open-general-licences/", json) return data.json(), data.status_code
def post_ecju_query_document(request, pk, query_pk, json): response = client.post(request, f"/cases/{pk}/ecju-queries/{query_pk}/document/", json) response.raise_for_status() return response.json(), response.status_code
def post_hmrc_organisations(request, json): data = client.post(request, "/organisations/", json) return data.json(), data.status_code
def post_queues(request, json): data = client.post(request, "/queues/", json) return data.json(), data.status_code
def post_gov_users(request, json): json.setdefault("first_name", "") json.setdefault("last_name", "") data = client.post(request, "/gov-users/", json) return data.json(), data.status_code
def post_sites_on_draft(request, pk, json): data = client.post(request, f"/applications/{pk}/sites/", json) return data.json(), data.status_code
def post_enforcement_xml(request, queue_pk, json): response = client.post(request, f"/cases/enforcement-check/{queue_pk}", json) return response
def post_external_locations_on_draft(request, pk, json): data = client.post(request, f"/applications/{pk}/external_locations/", json) return data.json(), data.status_code
def authenticate_gov_user(request, json): data = client.post(request, "/gov-users/authenticate/", json) return data.json(), data.status_code
def authenticate_exporter_user(request, json): data = client.post(request, "/users/authenticate/", json) return data.json(), data.status_code