diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2023-11-29 14:50:34 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2024-04-16 16:38:32 +0200 |
commit | 90945fb1ad016c6521ee8cfc0c336cdfe388c9f8 (patch) | |
tree | bdaba024b5904876b18c29366777e755343ad308 /ishtar_common/data_importer.py | |
parent | a8e52fddea741a19e95c61aede8185f9fdc2319b (diff) | |
download | Ishtar-90945fb1ad016c6521ee8cfc0c336cdfe388c9f8.tar.bz2 Ishtar-90945fb1ad016c6521ee8cfc0c336cdfe388c9f8.zip |
🐛 Imports: fix default data in table import (refs #5682)
Diffstat (limited to 'ishtar_common/data_importer.py')
-rw-r--r-- | ishtar_common/data_importer.py | 39 |
1 files changed, 25 insertions, 14 deletions
diff --git a/ishtar_common/data_importer.py b/ishtar_common/data_importer.py index df6b52c7c..3b7e4305e 100644 --- a/ishtar_common/data_importer.py +++ b/ishtar_common/data_importer.py @@ -1110,6 +1110,28 @@ class Importer(object): self._add_to_post_save(cls, obj.pk, idx_line) return obj + def _manage_geodata(self, default_srs, geodata, data, key="geodata"): + if key not in data: # no GIS information provided + return geodata + geodata.update(data.pop(key)) + + # manage geodata SRS + has_srs_field = False + for gk in geodata: + if gk.startswith("spatial_reference_system") and geodata[gk]: + has_srs_field = True + if isinstance(geodata[gk], dict) and "srid" in geodata[gk]: + srid = geodata[gk]["srid"] + if isinstance(srid, (str, int)): + SpatialReferenceSystem = apps.get_model("ishtar_common", "SpatialReferenceSystem") + q = SpatialReferenceSystem.objects.filter(srid=geodata[gk]["srid"]) + if q.count(): + geodata[gk] = q.all()[0] + break + if default_srs and not has_srs_field: + geodata["spatial_reference_system"] = default_srs + return geodata + def _line_processing(self, idx_line, line): self.timestamp = int(datetime.datetime.now().timestamp()) for item in self.to_be_close: @@ -1196,22 +1218,11 @@ class Importer(object): if self.TYPE == "gis": profile = get_current_profile() default_srs = profile.srs if profile.srs else None - if "geodata" in data: - geodata.update(data.pop("geodata")) - if default_srs and not [ - 1 for k in geodata if k.startswith("spatial_reference_system") and - geodata[k] - ]: - geodata["spatial_reference_system"] = default_srs - + geodata = self._manage_geodata(default_srs, geodata, data) if "main_geodata" in data: - main_geodata.update(data.pop("main_geodata")) - if default_srs and not [ - 1 for k in main_geodata if k.startswith("spatial_reference_system") - and main_geodata[k] - ]: - main_geodata["spatial_reference_system"] = default_srs + main_geodata = self._manage_geodata(default_srs, main_geodata, data, key="main_geodata") + # TODO: main_geodata not used? obj, created = self.get_object(self.OBJECT_CLS, data, idx_line=idx_line) if self.simulate: return data |