def post_compliance_person_present(request, case_id, json): data = post( request, COMPLIANCE_URL + COMPLIANCE_VISIT_URL + str(case_id) + "/" + COMPLIANCE_PEOPLE_PRESENT_URL, request_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["name-" + str(index)] = [str(index) + ". " + error.pop("name")[0]] if "job_title" in error: translated_errors["job-title-" + str(index)] = [str(index) + ". " + error.pop("job_title")[0]] index += 1 return {**json, "errors": translated_errors}, data.status_code return data.json(), data.status_code
def post_exhibition(request, pk, data): post_data = data post_data = format_date_fields(post_data) data = post(request, APPLICATIONS_URL + str(pk) + "/exhibition-details/", request_data=post_data) return data.json(), data.status_code
def post_good_documents(request, pk, json): if "description" not in json: json["description"] = "" json = [json] data = post(request, GOODS_URL + pk + DOCUMENTS_URL, json) return data.json(), data.status_code
def _register_organisation(request, json, _type): data = { "type": _type, "user": { "email": request.user.email }, } response = post(request, ORGANISATIONS_URL, {**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"), "report_summary": request.POST.get("report_summary"), } response = post(request, GOOD_CLC_REVIEW_URL + str(case_id) + "/", json) return response.json(), response.status_code
def post_external_locations(request, pk, json): data = post( request, ORGANISATIONS_URL + str(request.user.organisation) + EXTERNAL_LOCATIONS_URL, 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 = post(request, ORGANISATIONS_URL, json) return data.json(), data.status_code
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 = post(request, ENFORCEMENT_URL + str(queue_pk), file_format) 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 > 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 = post(request, OPEN_LICENCE_RETURNS_URL, json) return data.json(), data.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 = post(request, ORGANISATIONS_URL + str(organisation_id) + SITES_URL, json) return data.json(), data.status_code
def post_goods(request, json): 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 = post(request, GOODS_URL, json) if data.status_code == HTTPStatus.OK: data.json().get("good"), data.status_code return data.json(), data.status_code
def post_applications(request, json): data = post(request, APPLICATIONS_URL, json) return data.json(), data.status_code
def copy_application(request, pk, data): data = post(request, APPLICATIONS_URL + str(pk) + APPLICATION_COPY_URL, request_data=data) return data.json(), data.status_code
def post_goods_type_document(request, pk, good_pk, json): data = post( request, APPLICATIONS_URL + pk + GOODSTYPE_URL + str(good_pk) + DOCUMENT_URL, json) return data.json(), data.status_code
def post_goods_type(request, app_pk, json): data = post(request, APPLICATIONS_URL + str(app_pk) + GOODSTYPES_URL, json) return data.json(), data.status_code
def raise_goods_query(request, pk, json): post_data = json post_data["good_id"] = pk data = post(request, GOODS_QUERY_URL, post_data) return data.json(), data.status_code
def post_additional_document(request, pk, json): data = post(request, APPLICATIONS_URL + pk + ADDITIONAL_DOCUMENT_URL, json) return data.json(), data.status_code
def post_hmrc_organisations(request, json): data = post(request, ORGANISATIONS_URL, json) return data.json(), data.status_code
def submit_draft(request, pk): data = post(request, APPLICATIONS_URL, {'id': pk}) return data.json(), data.status_code
def post_application_countries(request, pk, json): data = post(request, APPLICATIONS_URL + str(pk) + COUNTRIES_URL, json) return data.json(), data.status_code
def post_good_on_application(request, pk, json): post_data = get_data_from_post_good_on_app(json) if "good_id" not in post_data: post_data["good_id"] = json["good_id"] data = post(request, APPLICATIONS_URL + str(pk) + GOODS_URL, post_data) return data.json(), data.status_code
def validate_application_good(request, pk, json): post_data = get_data_from_post_good_on_app(json) post_data["validate_only"] = True return post(request, APPLICATIONS_URL + pk + GOODS_URL, post_data)
def post_role(request, json): organisation_id = str(request.user.organisation) data = post(request, ORGANISATIONS_URL + str(organisation_id) + ROLES_URL, json) return data.json(), data.status_code
def post_case_notes(request, pk, json): data = post(request, CASES_URL + pk + CASE_NOTES_URL, json) return data.json(), data.status_code
def validate_party(request, pk, json): json = add_validate_only_to_data(json) data = post(request, APPLICATIONS_URL + str(pk) + PARTIES_URL, json) return data.json(), data.status_code
def post_good_document_sensitivity(request, pk, json): data = post(request, GOODS_URL + str(pk) + DOCUMENT_SENSITIVITY_URL, json) return data.json(), data.status_code
def post_drafts(request, json): data = post(request, DRAFTS_URL, json) return data.json(), data.status_code
def post_party(request, pk, json): data = post(request, APPLICATIONS_URL + str(pk) + PARTIES_URL, json) return data.json(), data.status_code
def post_draft_preexisting_goods(request, pk, json): data = post(request, DRAFTS_URL + pk + '/goods/', json) return data.json(), data.status_code
def post_party_document(request, application_pk, obj_pk, json): data = post(request, APPLICATIONS_URL + application_pk + PARTIES_URL + str(obj_pk) + DOCUMENT_URL, request_data=json) return data.json(), data.status_code