def _convert_document(party, document_type, application_id, editable): document = party.get("document") if not document: return default_na(None) if document["safe"] is None: return "Processing" if not document["safe"]: return convert_to_link( f"/applications/{application_id}/{document_type}/{party['id']}/document/attach/", Parties.Documents.VIRUS) if editable: return convert_to_link( f"/applications/{application_id}/{document_type}/{party['id']}/document/download", "Download", include_br=True, ) + convert_to_link( f"/applications/{application_id}/{document_type}/{party['id']}/document/delete", Parties.Documents.DELETE) else: return convert_to_link( f"/applications/{application_id}/{document_type}/{party['id']}/document/download", Parties.Documents.DOWNLOAD, include_br=True, )
def convert_country_contract_types(country): return default_na("\n".join([ ContractTypes.get_str_representation(ContractTypes(contract_type)) if contract_type != "other_contract_type" else "Other contract type - " + country["other_contract_type_text"] for contract_type in country["contract_types"] ]))
def _convert_goods(goods, is_exhibition=False): goods_list = [] for good in goods: goods_dict = { "Description": good["good"]["description"], "Part number": default_na(good["good"]["part_number"]), "Controlled": good["good"]["is_good_controlled"]["value"], "Control list entries": convert_control_list_entries(good["good"]["control_list_entries"]), } if is_exhibition: goods_dict["Product type"] = good["other_item_type"] if good[ "other_item_type"] else good["item_type"] else: goods_dict["Incorporated"] = friendly_boolean( good["is_good_incorporated"]) goods_dict["Quantity"] = ( intcomma(good["quantity"]) + " " + pluralise_unit(good["unit"]["value"], good["quantity"])) goods_dict["Value"] = "£" + good["value"] goods_list.append(goods_dict) return goods_list
def convert_control_list_entries(control_list_entries): return default_na( mark_safe( # nosec ", ".join([ "<span data-definition-title='" + clc["rating"] + "' data-definition-text='" + clc.get("text", "") + "'>" + clc["rating"] + "</span>" for clc in control_list_entries ])))
def _get_supporting_documentation(supporting_documentation, application_id): return [{ "File name": convert_to_link( reverse("applications:download_additional_document", kwargs={ "pk": application_id, "obj_pk": document["id"] }), document["name"], ), "Description": default_na(document["description"]), } for document in supporting_documentation]
def good_summary(good): if not good: return return Summary( values={ "Description": good["description"], "Control list entries": convert_control_list_entries(good["control_list_entries"]), "Part number": default_na(good["part_number"]), }, classes=["govuk-summary-list--no-border"], )
def convert_to_link(address, name=None, classes="", include_br=False): """ Returns a correctly formatted, safe link to an address Returns default_na if no address is provided """ if not address: return default_na(None) if not name: name = address address = escape(address) name = escape(name) br = "<br>" if include_br else "" return safe(f'<a href="{address}" class="govuk-link govuk-link--no-visited-state {classes}">{name}</a>{br}')
def convert_goods_on_application(goods_on_application, is_exhibition=False): converted = [] for good_on_application in goods_on_application: # TAU's review is saved at "good on application" level, while exporter's answer is at good level. if good_on_application["good"]["is_good_controlled"] is None: is_controlled = "N/A" else: is_controlled = good_on_application["good"]["is_good_controlled"][ "value"] control_list_entries = convert_control_list_entries( good_on_application["good"]["control_list_entries"]) if good_on_application["is_good_controlled"] is not None: is_controlled_application = good_on_application[ "is_good_controlled"]["value"] if is_controlled != is_controlled_application: is_controlled = f"<span class='strike'>{is_controlled}</span><br> {is_controlled_application}" control_list_application = convert_control_list_entries( good_on_application["control_list_entries"]) if control_list_entries != control_list_application: control_list_entries = f"<span class='strike'>{control_list_entries}</span> {control_list_application}" if good_on_application["good"].get("name"): name = good_on_application["good"]["name"] else: name = good_on_application["good"]["description"] item = { "Name": name, "Part number": default_na(good_on_application["good"]["part_number"]), "Controlled": mark_safe(is_controlled), # nosec "Control list entries": mark_safe(control_list_entries), # nosec } if is_exhibition: item["Product type"] = good_on_application[ "other_item_type"] or good_on_application["item_type"] else: item["Incorporated"] = friendly_boolean( good_on_application["is_good_incorporated"]) item["Quantity"] = pluralise_quantity(good_on_application) item["Value"] = f"£{good_on_application['value']}" converted.append(item) return converted
def good_summary(good): if not good: return values = { "Name": good["description"] if not good["name"] else good["name"], "Control list entries": convert_control_list_entries(good["control_list_entries"]), "Part number": default_na(good["part_number"]), } if good["item_category"]["key"] == PRODUCT_CATEGORY_FIREARM: firearm_type = good["firearm_details"]["type"]["key"] if firearm_type in FIREARM_AMMUNITION_COMPONENT_TYPES: values["Number of items"] = str( good["firearm_details"].get("number_of_items")) return Summary( values=values, classes=["govuk-summary-list--no-border"], )
def test_default_na_without_value(self): expected_value = '<span class="govuk-hint govuk-!-margin-0">N/A</span>' actual_value = ct.default_na(None) self.assertEqual(actual_value, expected_value)
def test_default_na_with_value(self): expected_value = 1 actual_value = ct.default_na(1) self.assertEqual(actual_value, expected_value)