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

Import cities warnings #187

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
35 changes: 22 additions & 13 deletions cities_light/management/commands/cities_light.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,10 @@ def region_import(self, items):
except InvalidItems:
return

force_insert = False
force_update = False

try:
force_insert = False
force_update = False
region = Region.objects.get(geoname_id=items[IRegion.geonameid])
force_update = True
except Region.DoesNotExist:
Expand Down Expand Up @@ -370,17 +371,6 @@ def city_import(self, items):
except InvalidItems:
return

try:
force_insert = False
force_update = False
city = City.objects.get(geoname_id=items[ICity.geonameid])
force_update = True
except City.DoesNotExist:
if self.noinsert:
return
city = City(geoname_id=items[ICity.geonameid])
force_insert = True

try:
country_id = self._get_country_id(items[ICity.countryCode])
except Country.DoesNotExist:
Expand All @@ -397,6 +387,25 @@ def city_import(self, items):
except Region.DoesNotExist:
region_id = None

force_insert = False
force_update = False

try:
city = City.objects.get(geoname_id=items[ICity.geonameid])
force_update = True
except City.DoesNotExist:
try:
# check on duplicate by unique key
city = City.objects.get(name=items[ICity.name],
region_id=region_id)
if city:
return
except City.DoesNotExist:
if self.noinsert:
return
city = City(geoname_id=items[ICity.geonameid])
force_insert = True

save = False
if city.country_id != country_id:
city.country_id = country_id
Expand Down