diff --git a/.gitignore b/.gitignore index 04cb6934..d25f2e07 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.venv .Python *.pyc *.orig diff --git a/src/cities_light/management/commands/cities_light.py b/src/cities_light/management/commands/cities_light.py index 3367000b..e9907404 100644 --- a/src/cities_light/management/commands/cities_light.py +++ b/src/cities_light/management/commands/cities_light.py @@ -187,7 +187,7 @@ def handle(self, *args, **options): if not os.path.exists(install_file_path): self.logger.info( 'Forced import of %s because data do not seem' - ' to have installed successfuly yet, note that this is' + ' to have installed successfully yet, note that this is' ' equivalent to --force-import-all.', destination_file_name) force_import = True @@ -231,12 +231,17 @@ def handle(self, *args, **options): if url in TRANSLATION_SOURCES and options.get( 'hack_translations', False): - with open(translation_hack_path, 'w+') as f: + with open(translation_hack_path, 'wb+') as f: pickle.dump(self.translation_data, f) if options.get('hack_translations', False): - with open(translation_hack_path, 'r') as f: - self.translation_data = pickle.load(f) + if os.path.getsize(translation_hack_path) > 0: + with open(translation_hack_path, 'rb') as f: + self.translation_data = pickle.load(f) + else: + self.logger.debug( + 'The translation file that you are trying to' + ' load is empty: %s', translation_hack_path) self.logger.info('Importing parsed translation in the database') self.translation_import() @@ -319,7 +324,7 @@ def country_import(self, items): country.continent = items[ICountry.continent] country.tld = items[ICountry.tld][1:] # strip the leading dot # Strip + prefix for consistency. Note that some countries have several - # prefixes ie. Puerto Rico + # prefixes i.e. Puerto Rico country.phone = items[ICountry.phone].replace('+', '') # Clear name_ascii to always update it by set_name_ascii() signal country.name_ascii = '' @@ -397,6 +402,7 @@ def region_import(self, items): ) def subregion_import(self, items): + try: subregion_items_pre_import.send(sender=self, items=items) except InvalidItems: @@ -593,11 +599,14 @@ def translation_parse(self, items): 'geoname_id', flat=True)) self.city_ids = set(City.objects.values_list( 'geoname_id', flat=True)) + self.subregion_ids = set(SubRegion.objects.values_list( + 'geoname_id', flat=True)) self.translation_data = collections.OrderedDict(( (Country, {}), (Region, {}), (City, {}), + (SubRegion, {}), )) # https://code.djangoproject.com/ticket/21597#comment:29 @@ -631,6 +640,8 @@ def translation_parse(self, items): model_class = Region elif item_geoid in self.city_ids: model_class = City + elif item_geoid in self.subregion_ids: + model_class = SubRegion else: return diff --git a/src/cities_light/tests/fixtures/import/angouleme.json b/src/cities_light/tests/fixtures/import/angouleme.json index 1b439203..b4a29cd8 100644 --- a/src/cities_light/tests/fixtures/import/angouleme.json +++ b/src/cities_light/tests/fixtures/import/angouleme.json @@ -31,7 +31,7 @@ }, { "fields": { - "alternate_names": "", + "alternate_names": "Département de la Charente", "country": [3017382], "display_name": "Charente, France", "geoname_code": "16", diff --git a/src/cities_light/tests/fixtures/import/angouleme_wtz.json b/src/cities_light/tests/fixtures/import/angouleme_wtz.json index 336cad4d..dab04d80 100644 --- a/src/cities_light/tests/fixtures/import/angouleme_wtz.json +++ b/src/cities_light/tests/fixtures/import/angouleme_wtz.json @@ -31,7 +31,7 @@ }, { "fields": { - "alternate_names": "", + "alternate_names": "Département de la Charente", "country": [3017382], "display_name": "Charente, France", "geoname_code": "16", diff --git a/src/cities_light/tests/fixtures/update/add_records.json b/src/cities_light/tests/fixtures/update/add_records.json index 88f14260..961cd084 100644 --- a/src/cities_light/tests/fixtures/update/add_records.json +++ b/src/cities_light/tests/fixtures/update/add_records.json @@ -91,7 +91,7 @@ }, { "fields": { - "alternate_names": "", + "alternate_names": "Юргинский район", "country": [2017370], "display_name": "Yurginskiy Rayon, Russia", "geoname_code": "1485714", diff --git a/src/cities_light/tests/fixtures/update/change_country.json b/src/cities_light/tests/fixtures/update/change_country.json index d6590f80..8e043f9c 100644 --- a/src/cities_light/tests/fixtures/update/change_country.json +++ b/src/cities_light/tests/fixtures/update/change_country.json @@ -77,7 +77,7 @@ }, { "fields": { - "alternate_names": "", + "alternate_names": "Юргинский район", "country": [2017370], "display_name": "Yurginskiy Rayon, Russia", "geoname_code": "1485714", @@ -92,7 +92,7 @@ }, { "fields": { - "alternate_names": "", + "alternate_names": "Хайленд", "country": [2635167], "display_name": "Highland, United Kingdom", "geoname_code": "V3", diff --git a/src/cities_light/tests/fixtures/update/change_region_and_country.json b/src/cities_light/tests/fixtures/update/change_region_and_country.json index 50df04fc..0b4d5a20 100644 --- a/src/cities_light/tests/fixtures/update/change_region_and_country.json +++ b/src/cities_light/tests/fixtures/update/change_region_and_country.json @@ -91,7 +91,7 @@ }, { "fields": { - "alternate_names": "", + "alternate_names": "Юргинский район", "country": [2017370], "display_name": "Yurginskiy Rayon, Russia", "geoname_code": "1485714", @@ -106,7 +106,7 @@ }, { "fields": { - "alternate_names": "", + "alternate_names": "Хайленд", "country": [2635167], "display_name": "Highland, United Kingdom", "geoname_code": "V3", diff --git a/src/cities_light/tests/fixtures/update/keep_slugs.json b/src/cities_light/tests/fixtures/update/keep_slugs.json index 8afe8b5a..17607e47 100644 --- a/src/cities_light/tests/fixtures/update/keep_slugs.json +++ b/src/cities_light/tests/fixtures/update/keep_slugs.json @@ -61,7 +61,7 @@ }, { "fields": { - "alternate_names": "", + "alternate_names": "Юргинский район", "country": [2017370], "display_name": "Yurginskiy Rayon, Russia", "geoname_code": "1485714", @@ -76,7 +76,7 @@ }, { "fields": { - "alternate_names": "", + "alternate_names": "Хайленд", "country": [2635167], "display_name": "Highland, United Kingdom", "geoname_code": "V3", diff --git a/src/cities_light/tests/fixtures/update/update_fields.json b/src/cities_light/tests/fixtures/update/update_fields.json index 14b12237..2fddb114 100644 --- a/src/cities_light/tests/fixtures/update/update_fields.json +++ b/src/cities_light/tests/fixtures/update/update_fields.json @@ -61,7 +61,7 @@ }, { "fields": { - "alternate_names": "", + "alternate_names": "Юргинский район", "country": [2017370], "display_name": "Yurginskiy Rayon, Russia", "geoname_code": "1485714", @@ -76,7 +76,7 @@ }, { "fields": { - "alternate_names": "", + "alternate_names": "Хайленд", "country": [2635167], "display_name": "Highland, United Kingdom", "geoname_code": "V3", diff --git a/src/cities_light/tests/fixtures/update/update_fields_wtz.json b/src/cities_light/tests/fixtures/update/update_fields_wtz.json index 68ea68d9..e12f0fe0 100644 --- a/src/cities_light/tests/fixtures/update/update_fields_wtz.json +++ b/src/cities_light/tests/fixtures/update/update_fields_wtz.json @@ -61,7 +61,7 @@ }, { "fields": { - "alternate_names": "", + "alternate_names": "Юргинский район", "country": [2017370], "display_name": "Yurginskiy Rayon, Russia", "geoname_code": "1485714", @@ -76,7 +76,7 @@ }, { "fields": { - "alternate_names": "", + "alternate_names": "Хайленд", "country": [2635167], "display_name": "Highland, United Kingdom", "geoname_code": "V3",