diff options
author | Étienne Loks <etienne.loks@peacefrogs.net> | 2019-02-07 13:05:12 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-04-24 19:38:56 +0200 |
commit | 4e8d9e04b16a18efc5f0f129a6ebd64935b681ec (patch) | |
tree | 542534dcb19d86f02c151cd469b453c064158ac3 | |
parent | b45b4353785924420078aad98ef5fb0fb26336fe (diff) | |
download | Ishtar-4e8d9e04b16a18efc5f0f129a6ebd64935b681ec.tar.bz2 Ishtar-4e8d9e04b16a18efc5f0f129a6ebd64935b681ec.zip |
Point save: fix source update
-rw-r--r-- | ishtar_common/utils.py | 50 |
1 files changed, 25 insertions, 25 deletions
diff --git a/ishtar_common/utils.py b/ishtar_common/utils.py index 0f33fd30d..d8650f098 100644 --- a/ishtar_common/utils.py +++ b/ishtar_common/utils.py @@ -473,14 +473,15 @@ def post_save_geo(sender, **kwargs): """ Convert raw x, y, z point to real geo field """ - from ishtar_common.models import SpatialReferenceSystem if not kwargs.get('instance'): return + from ishtar_common.models import SpatialReferenceSystem + from ishtar_common.models import get_current_profile # not clean but utils + # is loaded before models + instance = kwargs.get('instance') point = instance.point point_2d = instance.point_2d - from ishtar_common.models import get_current_profile # not clean but utils - # must be loaded before models profile = get_current_profile() modified = False @@ -508,32 +509,31 @@ def post_save_geo(sender, **kwargs): instance.point_2d = convert_coordinates_to_point( instance.point.x, instance.point.y, srid=current_point.srid) - elif not point_2d: - source = None - if 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 - 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 - if point_2d: - source = 'P' # precise - if instance.z: - point = convert_coordinates_to_point( - instance.x, instance.y, instance.z, - srid=instance.spatial_reference_system.srid) - elif profile.use_town_for_geo: # - point_2d = instance.get_town_centroid() - source = 'T' # town + elif not point_2d and profile.use_town_for_geo: # try to get from parent + point_2d = instance.get_town_centroid() + if point_2d != instance.point_2d: + instance.point_2d = point_2d + instance.point_source = 'T' # town + 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 + 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 + if instance.z: + point = convert_coordinates_to_point( + instance.x, instance.y, instance.z, + srid=instance.spatial_reference_system.srid) if point_2d != instance.point_2d or point != instance.point: instance.point = point instance.point_2d = point_2d - instance.point_source = source + instance.point_source = 'P' modified = True if instance.multi_polygon and not instance.multi_polygon_source: |