diff options
-rw-r--r-- | ishtar_common/management/commands/import_geofla_csv.py | 31 |
1 files changed, 11 insertions, 20 deletions
diff --git a/ishtar_common/management/commands/import_geofla_csv.py b/ishtar_common/management/commands/import_geofla_csv.py index 1657006f6..294219e9c 100644 --- a/ishtar_common/management/commands/import_geofla_csv.py +++ b/ishtar_common/management/commands/import_geofla_csv.py @@ -50,38 +50,29 @@ class Command(BaseCommand): if len(num_insee) < 5: num_insee = '0' + num_insee q = Town.objects.filter(numero_insee=num_insee) - changed, created = False, False + created = False if q.count(): if q.filter(year=default_year).count(): town = q.filter(year=default_year).all()[0] else: town = q.order_by('-year').all()[0] else: - changed = True created = True nb_created += 1 town = Town(name=row['NOM_COM'], numero_insee=num_insee) - if not town.limit: - changed = True - geom = row['wkt_geom'].upper() - if 'MULTI' not in geom: - geom = geom.replace('POLYGON', 'MULTIPOLYGON(') + ')' - town.limit = GEOSGeometry(geom, srid=2154) - if not town.center: - changed = True - town.center = Point(float(row['X_CENTROID']), - float(row['Y_CENTROID']), srid=2154) + geom = row['wkt_geom'].upper() + if 'MULTI' not in geom: + geom = geom.replace('POLYGON', 'MULTIPOLYGON(') + ')' + town.limit = GEOSGeometry(geom, srid=2154) + town.center = Point(float(row['X_CENTROID']), + float(row['Y_CENTROID']), srid=2154) if not town.year and default_year: - changed = True town.year = default_year - if not town.surface: - changed = True - town.surface = row['SUPERFICIE'] - if changed: - if not created: - nb_changed += 1 - town.save() + town.surface = row['SUPERFICIE'] + if not created: + nb_changed += 1 + town.save() sys.stdout.write('\n* {} town created'.format(nb_created)) sys.stdout.write('\n* {} town changed\n'.format(nb_changed)) sys.stdout.flush() |