diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2022-10-06 15:08:00 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2022-12-12 12:23:18 +0100 |
commit | f962ebab43441a1286fa17d882a0935720bb560c (patch) | |
tree | 244d0a52b1253e2580ab25d71dcb4d0f84f141fc /ishtar_common/utils.py | |
parent | 8d5a3dab0263aa1a6ceae34254bbf4aaffd2087a (diff) | |
download | Ishtar-f962ebab43441a1286fa17d882a0935720bb560c.tar.bz2 Ishtar-f962ebab43441a1286fa17d882a0935720bb560c.zip |
Geodata: cascade add
Diffstat (limited to 'ishtar_common/utils.py')
-rw-r--r-- | ishtar_common/utils.py | 192 |
1 files changed, 0 insertions, 192 deletions
diff --git a/ishtar_common/utils.py b/ishtar_common/utils.py index a99a40d02..6ffda0eb6 100644 --- a/ishtar_common/utils.py +++ b/ishtar_common/utils.py @@ -871,198 +871,6 @@ def _post_save_geo(sender, **kwargs): instance.cascade_update() cache_key, __ = get_cache(sender, ["post_save_geo", instance.pk]) cache.set(cache_key, None, settings.CACHE_TASK_TIMEOUT) - - return - # TODO to delete - - kls_name = instance.__class__.__name__ - - if not profile.locate_warehouses and ( - "Container" in kls_name or "Warehouse" in kls_name - ): - return - - if getattr(instance, "_post_saved_geo", False): - return - - # print(sender, "post_save_geo") - - current_source = "default" - if hasattr(instance.__class__, "_meta"): - current_source = str(instance.__class__._meta.verbose_name) - - modified = False - if hasattr(instance, "multi_polygon") and not getattr( - instance, "DISABLE_POLYGONS", False - ): - if ( - instance.multi_polygon_source_item - and instance.multi_polygon_source_item != current_source - ): # refetch - instance.multi_polygon = None - instance.multi_polygon_source = None - modified = True - - if instance.multi_polygon and not instance.multi_polygon_source: - # should be a db source - instance.multi_polygon_source = "P" - instance.multi_polygon_source_item = current_source - elif instance.multi_polygon_source != "P": - precise_poly = instance.get_precise_polygons() - if precise_poly: - poly, source_item = precise_poly - instance.multi_polygon = poly - instance.multi_polygon_source = "P" - instance.multi_polygon_source_item = source_item - modified = True - elif profile.use_town_for_geo: - poly = instance.get_town_polygons() - if poly: - poly, poly_source = poly - if poly != instance.multi_polygon: - instance.multi_polygon_source_item = poly_source - instance.multi_polygon_source = "T" # town - try: - instance.multi_polygon = poly - modified = True - except TypeError: - print(instance, instance.pk) - - if ( - instance.point_source_item and instance.point_source_item != current_source - ) or ( - instance.point_source == "M" - ): # refetch - csrs = instance.spatial_reference_system - - if instance.x and instance.y: - new_point = GEOSGeometry( - "POINT({} {})".format(instance.x, instance.y), srid=csrs.srid - ) - if instance.point_2d: - proj_point = instance.point_2d.transform(csrs.srid, clone=True) - if new_point.distance(proj_point) < 0.01: - instance.x, instance.y = None, None - instance.point, instance.point_2d = None, None - instance.point_source = None - - point = instance.point - point_2d = instance.point_2d - - if ( - (point or point_2d) and instance.x is None and not instance.point_source - ): # db source - if point: - current_point = point - instance.z = point.z - else: - current_point = point_2d - instance.x = current_point.x - instance.y = current_point.y - srs = get_srid_obj_from_point(current_point) - instance.spatial_reference_system = srs - instance.point_source = "P" - instance.point_source_item = current_source - if not point_2d: - instance.point_2d = convert_coordinates_to_point( - instance.point.x, instance.point.y, srid=current_point.srid - ) - modified = True - elif ( - instance.x - and instance.y - and instance.spatial_reference_system - and instance.spatial_reference_system.auth_name == "EPSG" - and instance.spatial_reference_system.srid != 0 - ): - # form input or already precise - try: - point_2d = convert_coordinates_to_point( - instance.x, instance.y, srid=instance.spatial_reference_system.srid - ) - except forms.ValidationError: - return # irrelevant data in DB - distance = 1 # arbitrary - if point_2d and instance.point_2d: - distance = point_2d.transform(4326, clone=True).distance( - instance.point_2d.transform(4326, clone=True) - ) - - if instance.z: - point = convert_coordinates_to_point( - instance.x, - instance.y, - instance.z, - srid=instance.spatial_reference_system.srid, - ) - - # no change if distance inf to 1 mm - if distance >= 0.0001 and ( - point_2d != instance.point_2d or point != instance.point - ): - instance.point = point - instance.point_2d = point_2d - instance.point_source = "P" - instance.point_source_item = current_source - modified = True - else: - instance.point_source = None - # get coordinates from parents - precise_points = instance.get_precise_points() - if not (instance.multi_polygon and instance.multi_polygon_source == "P") and \ - precise_points: - point_2d, point, source_item = precise_points - instance.point_2d = point_2d - instance.point = point - instance.point_source = "P" - instance.point_source_item = source_item - instance.x = point_2d.x - instance.y = point_2d.y - if point: - instance.z = point.z - srs = get_srid_obj_from_point(point_2d) - instance.spatial_reference_system = srs - modified = True - else: - centroid, source, point_source = None, None, None - if instance.multi_polygon and instance.multi_polygon_source == "P": - source = current_source - centroid = instance.multi_polygon.centroid - point_source = "M" - if not centroid and profile.use_town_for_geo: # try to get from - # parent - town_centroid = instance.get_town_centroid() - if town_centroid: - centroid, source = town_centroid - point_source = "T" - if centroid: - instance.point_2d, instance.point_source_item = centroid, source - instance.point = None - instance.point_source = point_source - instance.x = instance.point_2d.x - instance.y = instance.point_2d.y - srs = get_srid_obj_from_point(instance.point_2d) - instance.spatial_reference_system = srs - modified = True - else: - instance.point_2d, instance.point_source_item = None, None - instance.point = None - instance.point_source = None - modified = True - - if hasattr(instance, "need_update") and instance.need_update: - instance.need_update = False - modified = True - - if modified: - instance.skip_history_when_saving = True - instance._post_saved_geo = True - instance._cached_label_checked = False - instance.save() - if hasattr(instance, "cascade_update"): - instance.cascade_update() - cache_key, __ = get_cache(sender, ["post_save_geo", instance.pk]) - cache.set(cache_key, None, settings.CACHE_TASK_TIMEOUT) return |