diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2022-09-12 22:19:42 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2022-12-12 12:23:18 +0100 |
commit | a321a9da45e5fa4288a59a8a310a6e14e39ce702 (patch) | |
tree | 1b78e18dea1018b0708d3a9d1e3f222e9ae02680 /ishtar_common/management | |
parent | d183100d821d61d97715317189baa36e170decdb (diff) | |
download | Ishtar-a321a9da45e5fa4288a59a8a310a6e14e39ce702.tar.bz2 Ishtar-a321a9da45e5fa4288a59a8a310a6e14e39ce702.zip |
Geo - migration script: more tolerant with no geo item data - main geo is poly when defined
Diffstat (limited to 'ishtar_common/management')
-rw-r--r-- | ishtar_common/management/commands/migrate_to_geo_v4.py | 47 |
1 files changed, 32 insertions, 15 deletions
diff --git a/ishtar_common/management/commands/migrate_to_geo_v4.py b/ishtar_common/management/commands/migrate_to_geo_v4.py index 63a074363..11e4f7b76 100644 --- a/ishtar_common/management/commands/migrate_to_geo_v4.py +++ b/ishtar_common/management/commands/migrate_to_geo_v4.py @@ -64,11 +64,11 @@ model_slug, model_name, model_full_name, model = None, None, None, None model_content_type, data_type_area, data_type_center = None, None, None cls_labels = { - "ContextRecord": ["Context Record", "Unité d'Enregistrement"], - "BaseFind": ["Base find", "Mobilier d'origine"], - "Operation": ["Operation", "Opération"], + "ContextRecord": ["Context Record", "Unité d'Enregistrement", "", None], + "BaseFind": ["Base find", "Mobilier d'origine", "", None], + "Operation": ["Operation", "Opération", "", None], "ArchaeologicalSite": ["Entité (EA)", "Entité archéologique", - "Archaeological site"], + "Archaeological site", "", None], } @@ -89,6 +89,7 @@ def _process_site_ope(obj): [model_slug, str(obj), obj.pk, "Association géo de commune"] ) obj_verbose_names = cls_labels[obj.__class__.__name__] + has_poly = False if obj.multi_polygon_source == "P" and obj.multi_polygon \ and obj.multi_polygon_source_item in obj_verbose_names: if debug: @@ -104,6 +105,7 @@ def _process_site_ope(obj): obj.main_geodata = data obj._post_save_geo_ok = False obj.save() + has_poly = True changed.append( [ "geovectordata", @@ -128,8 +130,12 @@ def _process_site_ope(obj): "spatial_reference_system": obj.spatial_reference_system } data = models_common.GeoVectorData.objects.create(**attrs) - obj.main_geodata = data - obj.save() + if not has_poly: + obj.main_geodata = data + obj._post_save_geo_ok = False + obj.save() + else: + obj.geodata.add(data) changed.append( [ "geovectordata", @@ -152,9 +158,12 @@ def _process_site_ope(obj): else: attrs["point_2d"] = obj.point_2d data = models_common.GeoVectorData.objects.create(**attrs) - obj.main_geodata = data - obj._post_save_geo_ok = False - obj.save() + if not has_poly: + obj.main_geodata = data + obj._post_save_geo_ok = False + obj.save() + else: + obj.geodata.add(data) changed.append( ["geovectordata", data.name, data.pk, f"Point {model_name}"] ) @@ -173,6 +182,7 @@ def _process_main(obj): [model_slug, str(obj), obj.pk, "Association géo de zone communale"] ) obj_verbose_names = cls_labels[obj.__class__.__name__] + has_poly = False if obj.multi_polygon_source == "P" and obj.multi_polygon \ and (obj.multi_polygon_source_item in obj_verbose_names or obj.multi_polygon_source_item in (None, "")): @@ -186,6 +196,7 @@ def _process_main(obj): data = models_common.GeoVectorData.objects.create(**attrs) obj.main_geodata = data obj._post_save_geo_ok = False + has_poly = True obj.save() changed.append( [ @@ -210,9 +221,12 @@ def _process_main(obj): "spatial_reference_system": obj.spatial_reference_system } data = models_common.GeoVectorData.objects.create(**attrs) - obj.main_geodata = data - obj._post_save_geo_ok = False - obj.save() + if not has_poly: + obj.main_geodata = data + obj._post_save_geo_ok = False + obj.save() + else: + obj.geodata.add(data) changed.append( [ "geovectordata", @@ -233,9 +247,12 @@ def _process_main(obj): else: attrs["point_2d"] = obj.point_2d data = models_common.GeoVectorData.objects.create(**attrs) - obj.main_geodata = data - obj._post_save_geo_ok = False - obj.save() + if not has_poly: + obj.main_geodata = data + obj._post_save_geo_ok = False + obj.save() + else: + obj.geodata.add(data) changed.append( ["geovectordata", data.name, data.pk, f"Point {model_name}"] ) |