Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add alternative names for SubRegion #282

Merged
merged 6 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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 @@

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:

Check warning on line 234 in src/cities_light/management/commands/cities_light.py

View check run for this annotation

Codecov / codecov/patch

src/cities_light/management/commands/cities_light.py#L234

Added line #L234 was not covered by tests
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)

Check warning on line 240 in src/cities_light/management/commands/cities_light.py

View check run for this annotation

Codecov / codecov/patch

src/cities_light/management/commands/cities_light.py#L238-L240

Added lines #L238 - L240 were not covered by tests
else:
self.logger.debug(

Check warning on line 242 in src/cities_light/management/commands/cities_light.py

View check run for this annotation

Codecov / codecov/patch

src/cities_light/management/commands/cities_light.py#L242

Added line #L242 was not covered by tests
'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 @@
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 subregion_import(self, items):

try:
subregion_items_pre_import.send(sender=self, items=items)
except InvalidItems:
Expand Down Expand Up @@ -593,11 +599,14 @@
'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 @@
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
Loading