Пример #1
0
def set_country_for_address(address):
    if address and "country_code" in address:
        try:
            address["country"] = country_code_to_name(address["country_code"])
        except KeyError:
            LOGGER.warning("Wrong Country code",
                           country_code=address["country_code"])
    return address
Пример #2
0
    def convert_to_form_data(self, data):
        speakers = data.get_value("speakers", [])
        for speaker in speakers:
            affiliation = get_value(speaker, "affiliations[0]")
            if affiliation:
                affiliation_value = affiliation.get("value")
                affiliation_record = affiliation.get("record")
                speaker["affiliation"] = affiliation_value
                if affiliation_record:
                    speaker["affiliation_record"] = affiliation_record
                del speaker["affiliations"]

        address = data.get_value("address")
        if address and "country_code" in address:
            address["country"] = country_code_to_name(address["country_code"])
            del address["country_code"]

        if address and "cities" in address:
            address["city"] = get_value(address, "cities[0]")
            del address["cities"]

        timezone = data.get("timezone")

        start_datetime = data.get("start_datetime")
        form_start_datetime = iso_utc_to_local_form_datetime(start_datetime, timezone)

        end_datetime = data.get("end_datetime")
        form_end_datetime = iso_utc_to_local_form_datetime(end_datetime, timezone)

        literature_records = [
            PidStoreBase.get_pid_from_record_uri(rec["record"]["$ref"])[1]
            for rec in data.get("literature_records", [])
        ]

        processed_data = {
            "name": data.get_value("title.title", missing),
            "additional_info": data.get_value("public_notes[0].value", missing),
            "address": address or missing,
            "speakers": speakers,
            "contacts": data.get_value("contact_details", missing),
            "series_name": data.get_value("series[0].name", missing),
            "series_number": data.get_value("series[0].number", missing),
            "field_of_interest": data.get_value("inspire_categories.term", missing),
            "dates": [form_start_datetime, form_end_datetime],
            "websites": data.get_value("urls.value", missing),
            "material_urls": data.get_value("material_urls", missing),
            "join_urls": data.get_value("join_urls", missing),
            "captioned": data.get("captioned", missing),
            "timezone": timezone,
            "abstract": data.get_value("abstract.value", missing),
            "keywords": data.get_value("keywords.value", missing),
            "literature_records": literature_records or missing,
        }
        return processed_data
Пример #3
0
def test_code_to_name_uses_prefers_current_country_over_old_country():
    assert utils.country_code_to_name("SK") == "Slovakia"
Пример #4
0
def test_code_to_name_with_common_name(country_code, expected):
    assert utils.country_code_to_name(country_code) == expected