Skip to content

Commit

Permalink
Add alternative names for SubRegion (#282)
Browse files Browse the repository at this point in the history
* add .venv to .gitignore

* add alternative names for subregion

* test name

* test update

* test update

* qa update

---------

Co-authored-by: marianoeramirez <Sosinformatico1990>
  • Loading branch information
ahmad88me authored Oct 18, 2023
1 parent 499fe89 commit bd0743e
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 18 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.venv
.Python
*.pyc
*.orig
Expand Down
21 changes: 16 additions & 5 deletions src/cities_light/management/commands/cities_light.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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 = ''
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/cities_light/tests/fixtures/import/angouleme.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
},
{
"fields": {
"alternate_names": "",
"alternate_names": "Département de la Charente",
"country": [3017382],
"display_name": "Charente, France",
"geoname_code": "16",
Expand Down
2 changes: 1 addition & 1 deletion src/cities_light/tests/fixtures/import/angouleme_wtz.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
},
{
"fields": {
"alternate_names": "",
"alternate_names": "Département de la Charente",
"country": [3017382],
"display_name": "Charente, France",
"geoname_code": "16",
Expand Down
2 changes: 1 addition & 1 deletion src/cities_light/tests/fixtures/update/add_records.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
},
{
"fields": {
"alternate_names": "",
"alternate_names": "Юргинский район",
"country": [2017370],
"display_name": "Yurginskiy Rayon, Russia",
"geoname_code": "1485714",
Expand Down
4 changes: 2 additions & 2 deletions src/cities_light/tests/fixtures/update/change_country.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
},
{
"fields": {
"alternate_names": "",
"alternate_names": "Юргинский район",
"country": [2017370],
"display_name": "Yurginskiy Rayon, Russia",
"geoname_code": "1485714",
Expand All @@ -92,7 +92,7 @@
},
{
"fields": {
"alternate_names": "",
"alternate_names": "Хайленд",
"country": [2635167],
"display_name": "Highland, United Kingdom",
"geoname_code": "V3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
},
{
"fields": {
"alternate_names": "",
"alternate_names": "Юргинский район",
"country": [2017370],
"display_name": "Yurginskiy Rayon, Russia",
"geoname_code": "1485714",
Expand All @@ -106,7 +106,7 @@
},
{
"fields": {
"alternate_names": "",
"alternate_names": "Хайленд",
"country": [2635167],
"display_name": "Highland, United Kingdom",
"geoname_code": "V3",
Expand Down
4 changes: 2 additions & 2 deletions src/cities_light/tests/fixtures/update/keep_slugs.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
},
{
"fields": {
"alternate_names": "",
"alternate_names": "Юргинский район",
"country": [2017370],
"display_name": "Yurginskiy Rayon, Russia",
"geoname_code": "1485714",
Expand All @@ -76,7 +76,7 @@
},
{
"fields": {
"alternate_names": "",
"alternate_names": "Хайленд",
"country": [2635167],
"display_name": "Highland, United Kingdom",
"geoname_code": "V3",
Expand Down
4 changes: 2 additions & 2 deletions src/cities_light/tests/fixtures/update/update_fields.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
},
{
"fields": {
"alternate_names": "",
"alternate_names": "Юргинский район",
"country": [2017370],
"display_name": "Yurginskiy Rayon, Russia",
"geoname_code": "1485714",
Expand All @@ -76,7 +76,7 @@
},
{
"fields": {
"alternate_names": "",
"alternate_names": "Хайленд",
"country": [2635167],
"display_name": "Highland, United Kingdom",
"geoname_code": "V3",
Expand Down
4 changes: 2 additions & 2 deletions src/cities_light/tests/fixtures/update/update_fields_wtz.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
},
{
"fields": {
"alternate_names": "",
"alternate_names": "Юргинский район",
"country": [2017370],
"display_name": "Yurginskiy Rayon, Russia",
"geoname_code": "1485714",
Expand All @@ -76,7 +76,7 @@
},
{
"fields": {
"alternate_names": "",
"alternate_names": "Хайленд",
"country": [2635167],
"display_name": "Highland, United Kingdom",
"geoname_code": "V3",
Expand Down

0 comments on commit bd0743e

Please sign in to comment.