Esempio n. 1
0
def forwards(apps, schema_editor):
    Country = apps.get_model('core.Country')

    cc = 0
    for cnt in Country.objects.all():
        if Country2.get_country_info_from_iso2(
                cnt.country_code)['#region+name+preferred+sub']:
            cnt.regionname = Country2.get_country_info_from_iso2(
                cnt.country_code)['#region+name+preferred+sub']
            cnt.region_code = Country2.get_country_info_from_iso2(
                cnt.country_code)['#region+code+sub']
            cnt.save()
        elif Country2.get_country_info_from_iso2(
                cnt.country_code)['#region+main+name+preferred']:
            cnt.regionname = Country2.get_country_info_from_iso2(
                cnt.country_code)['#region+main+name+preferred']
            cnt.region_code = Country2.get_country_info_from_iso2(
                cnt.country_code)['#region+code+main']
            cnt.save()
        else:
            cnt.regionname = Country2.get_country_info_from_iso2(
                cnt.country_code)['#country+name+preferred']
            cnt.region_code = Country2.get_country_info_from_iso2(
                cnt.country_code)['#country+code+v_iso2']
            cnt.save()
        cc += 1
        if cc % 300 == 0:
            print(cc)  #to keep track of progress
Esempio n. 2
0
 def test_get_country_info_from_iso2(self):
     assert Country.get_country_info_from_iso2('jp', use_live=False) == {
         '#country+alt+i_ar+name+v_unterm': 'اليابان',
         '#country+alt+i_en+name+v_unterm': 'Japan',
         '#country+alt+i_es+name+v_unterm': 'Japón (el)',
         '#country+alt+i_fr+name+v_unterm': 'Japon (le)',
         '#country+alt+i_ru+name+v_unterm': 'Япония',
         '#country+alt+i_zh+name+v_unterm': '日本',
         '#country+alt+name+v_fts': '',
         '#country+alt+name+v_hrinfo_country': '',
         '#country+alt+name+v_iso': '',
         '#country+alt+name+v_m49': '',
         '#country+alt+name+v_reliefweb': '',
         '#country+alt+name+v_unterm': '',
         '#country+code+num+v_m49': '392',
         '#country+code+v_fts': '112',
         '#country+code+v_hrinfo_country': '292',
         '#country+code+v_iso2': 'JP',
         '#country+code+v_iso3': 'JPN',
         '#country+code+v_reliefweb': '128',
         '#country+name+preferred': 'Japan',
         '#country+name+short+v_reliefweb': '',
         '#country+regex': 'japan',
         '#geo+admin_level': '0',
         '#geo+lat': '37.63209801',
         '#geo+lon': '138.0812256',
         '#meta+id': '112',
         '#region+code+intermediate': '',
         '#region+code+main': '142',
         '#region+code+sub': '30',
         '#region+intermediate+name+preferred': '',
         '#region+main+name+preferred': 'Asia',
         '#region+name+preferred+sub': 'Eastern Asia'
     }
     assert Country.get_country_info_from_iso2('ab', use_live=False) is None
     assert Country.get_country_info_from_iso2('TW', use_live=False) == {
         '#country+alt+i_ar+name+v_unterm': '',
         '#country+alt+i_en+name+v_unterm': 'Taiwan',
         '#country+alt+i_es+name+v_unterm': '',
         '#country+alt+i_fr+name+v_unterm': '',
         '#country+alt+i_ru+name+v_unterm': '',
         '#country+alt+i_zh+name+v_unterm': '',
         '#country+alt+name+v_fts': 'Taiwan, Province of China',
         '#country+alt+name+v_hrinfo_country': 'Taiwan, Province of China',
         '#country+alt+name+v_iso': '',
         '#country+alt+name+v_m49': '',
         '#country+alt+name+v_reliefweb': 'China - Taiwan Province',
         '#country+alt+name+v_unterm': '',
         '#country+code+num+v_m49': '158',
         '#country+code+v_fts': '219',
         '#country+code+v_hrinfo_country': '399',
         '#country+code+v_iso2': 'TW',
         '#country+code+v_iso3': 'TWN',
         '#country+code+v_reliefweb': '61',
         '#country+name+preferred': 'Taiwan (Province of China)',
         '#country+name+short+v_reliefweb': '',
         '#country+regex':
         '.*taiwan|.*taipei|.*formosa|^(?!.*\\bdem)(?!.*\\bpe)(?!.*\\bdr)(^rep.*).*\\bchina.*(?!.*\\bdem.*)(?!\\bpe.*)(?!.*\\bdr.*).*|^ROC$',
         '#geo+admin_level': '0',
         '#geo+lat': '23.74652012',
         '#geo+lon': '120.9621301',
         '#meta+id': '218',
         '#region+code+intermediate': '',
         '#region+code+main': '142',
         '#region+code+sub': '30',
         '#region+intermediate+name+preferred': '',
         '#region+main+name+preferred': 'Asia',
         '#region+name+preferred+sub': 'Eastern Asia'
     }
     with pytest.raises(LocationError):
         Country.get_country_info_from_iso2('ab',
                                            use_live=False,
                                            exception=LocationError)
    def test_get_country_info_from_iso2(self):
        assert Country.get_country_info_from_iso2('jp') == {
            '#country+alt+i_ar+name+v_unterm': 'اليابان',
            '#country+alt+i_en+name+v_unterm': 'Japan',
            '#country+alt+i_es+name+v_unterm': 'Japón (el)',
            '#country+alt+i_fr+name+v_unterm': 'Japon (le)',
            '#country+alt+i_ru+name+v_unterm': 'Япония',
            '#country+alt+i_zh+name+v_unterm': '日本',
            '#country+alt+name+v_fts': '',
            '#country+alt+name+v_hrinfo_country': '',
            '#country+alt+name+v_iso': '',
            '#country+alt+name+v_m49': '',
            '#country+alt+name+v_reliefweb': '',
            '#country+alt+name+v_unterm': '',
            '#country+code+num+v_m49': '392',
            '#country+code+v_fts': '112',
            '#country+code+v_hrinfo_country': '292',
            '#country+code+v_iso2': 'JP',
            '#country+code+v_iso3': 'JPN',
            '#country+code+v_reliefweb': '128',
            '#country+name+preferred': 'Japan',
            '#country+name+short+v_reliefweb': '',
            '#country+regex': 'japan',
            '#geo+admin_level': '0',
            '#geo+lat': '37.63209801',
            '#geo+lon': '138.0812256',
            '#meta+id': '112',
            '#region+code+intermediate': '',
            '#region+code+main': '142',
            '#region+code+sub': '30',
            '#region+intermediate+name+preferred': '',
            '#region+main+name+preferred': 'Asia',
            '#region+name+preferred+sub': 'Eastern Asia'}
        assert Country.get_country_info_from_iso2('ab') is None
        assert Country.get_country_info_from_iso2('TW') == {
            '#country+alt+i_ar+name+v_unterm': '',
            '#country+alt+i_en+name+v_unterm': 'Taiwan',
            '#country+alt+i_es+name+v_unterm': '',
            '#country+alt+i_fr+name+v_unterm': '',
            '#country+alt+i_ru+name+v_unterm': '',
            '#country+alt+i_zh+name+v_unterm': '',
            '#country+alt+name+v_fts': 'Taiwan, Province of China',
            '#country+alt+name+v_hrinfo_country': 'Taiwan, Province of China',
            '#country+alt+name+v_iso': '',
            '#country+alt+name+v_m49': '',
            '#country+alt+name+v_reliefweb': 'China - Taiwan Province',
            '#country+alt+name+v_unterm': '',
            '#country+code+num+v_m49': '158',
            '#country+code+v_fts': '219',
            '#country+code+v_hrinfo_country': '399',
            '#country+code+v_iso2': 'TW',
            '#country+code+v_iso3': 'TWN',
            '#country+code+v_reliefweb': '61',
            '#country+name+preferred': 'Taiwan (Province of China)',
            '#country+name+short+v_reliefweb': '',
            '#country+regex': '.*taiwan|.*taipei|.*formosa|^(?!.*\\bdem)(?!.*\\bpe)(?!.*\\bdr)(^rep.*).*\\bchina.*(?!.*\\bdem.*)(?!\\bpe.*)(?!.*\\bdr.*).*|^ROC$',
            '#geo+admin_level': '0',
            '#geo+lat': '23.74652012',
            '#geo+lon': '120.9621301',
            '#meta+id': '218',
            '#region+code+intermediate': '',
            '#region+code+main': '142',
            '#region+code+sub': '30',
            '#region+intermediate+name+preferred': '',
            '#region+main+name+preferred': 'Asia',
            '#region+name+preferred+sub': 'Eastern Asia'}

        assert Country.get_country_info_from_iso2('PS') == {
            '#meta+id': '170',
            '#country+code+v_hrinfo_country': '351',
            '#country+code+v_reliefweb': '180',
            '#country+code+num+v_m49': '275',
            '#country+code+v_fts': '171',
            '#country+code+v_iso2': 'PS',
            '#country+code+v_iso3': 'PSE',
            '#country+name+preferred': 'State of Palestine',
            '#country+alt+name+v_m49': '',
            '#country+alt+name+v_iso': 'Palestine, State of',
            '#country+alt+name+v_unterm': '',
            '#country+alt+name+v_fts': 'occupied Palestinian territory',
            '#country+alt+name+v_hrinfo_country': 'occupied Palestinian territory',
            '#country+name+short+v_reliefweb': 'oPt',
            '#country+alt+name+v_reliefweb': 'occupied Palestinian territory',
            '#country+alt+i_en+name+v_unterm': 'Palestine',
            '#country+alt+i_fr+name+v_unterm': 'État de Palestine',
            '#country+alt+i_es+name+v_unterm': 'Estado de Palestina',
            '#country+alt+i_ru+name+v_unterm': 'Государство Палестина',
            '#country+alt+i_zh+name+v_unterm': '巴勒斯坦国',
            '#country+alt+i_ar+name+v_unterm': 'دولة فلسطين',
            '#geo+admin_level': '0',
            '#geo+lat': '31.99084142',
            '#geo+lon': '35.30744047',
            '#region+code+main': '142',
            '#region+main+name+preferred': 'Asia',
            '#region+code+sub': '145',
            '#region+name+preferred+sub': 'Western Asia',
            '#region+code+intermediate': '',
            '#region+intermediate+name+preferred': '',
            '#country+regex': 'palestin|\\bgaza|west.?bank',
            '#country+name+override': 'oPt'}
        with pytest.raises(LocationError):
            Country.get_country_info_from_iso2('ab', exception=LocationError)