diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2022-08-08 23:11:09 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2022-12-12 12:23:17 +0100 |
commit | 6e626e92a01722dd2814e8827753ed0e1a653f9b (patch) | |
tree | 56e8e0baab7704e2ce1beeb24478706202ff246f /ishtar_common/data_importer.py | |
parent | 371e2bbff3d9d71baeb2a26ab2c1ec9ad3a86a13 (diff) | |
download | Ishtar-6e626e92a01722dd2814e8827753ed0e1a653f9b.tar.bz2 Ishtar-6e626e92a01722dd2814e8827753ed0e1a653f9b.zip |
Import: manage CSV geo data
Diffstat (limited to 'ishtar_common/data_importer.py')
-rw-r--r-- | ishtar_common/data_importer.py | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/ishtar_common/data_importer.py b/ishtar_common/data_importer.py index 5090fb15b..61c294b28 100644 --- a/ishtar_common/data_importer.py +++ b/ishtar_common/data_importer.py @@ -39,7 +39,7 @@ from django.db.models import Q from django.template.defaultfilters import slugify from django.utils.translation import ugettext_lazy as _ -from ishtar_common.utils import debug_line_no, get_all_field_names, update_data +from ishtar_common.utils import get_all_field_names, update_data, get_current_profile NEW_LINE_BREAK = "#####@@@#####" @@ -864,6 +864,9 @@ class Importer(object): "{} with values {} doesn't exist in the " "database. Create it first or fix your source file." ), + "gis_missing_obj": _( + "Related object not found. Can not create the geographic item. Context: {}." + ) } def _create_models(self, force=False): @@ -1373,11 +1376,24 @@ class Importer(object): self.new_objects, self.updated_objects = [], [] self.ambiguous_objects, self.not_find_objects = [], [] - geodata = {} + geodata, main_geodata = {}, {} if self.TYPE == "gis": + profile = get_current_profile() + default_srs = profile.srs if profile.srs else None + if "geodata" in data: geodata = self._defaults.get(("geodata",), {}) geodata.update(data.pop("geodata")) + if default_srs and not [ + 1 for k in geodata if k.startswith("spatial_reference_system")]: + geodata["spatial_reference_system"] = default_srs + + if "main_geodata" in data: + main_geodata = self._defaults.get(("main_geodata",), {}) + main_geodata.update(data.pop("main_geodata")) + if default_srs and not [ + 1 for k in main_geodata if k.startswith("spatial_reference_system")]: + main_geodata["spatial_reference_system"] = default_srs obj, created = self.get_object(self.OBJECT_CLS, data, idx_line=idx_line) if self.simulate: return data @@ -1401,6 +1417,17 @@ class Importer(object): self._add_to_post_save(obj.__class__, obj.pk, idx_line) if self.TYPE == "gis": + if not obj and not self.c_errors: + self.c_errors = True + self.errors.append( + ( + idx_line + 1, + "-", + self.ERRORS["gis_missing_obj"].format(str(data)), + ) + ) + return + content_type = ContentType.objects.get( app_label=obj.__class__._meta.app_label, model=obj.__class__.__name__.lower() |