summaryrefslogtreecommitdiff
path: root/ishtar_common/models_common.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2022-10-12 11:38:13 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2022-12-12 12:23:18 +0100
commit8e002b956ea2b53d31a544cc149c18fd6d910a17 (patch)
treedc91a1f0efc1a475345acacfa6aba384629da16c /ishtar_common/models_common.py
parent314e8ac660877752acf0a353e2833e4b0c500ccb (diff)
downloadIshtar-8e002b956ea2b53d31a544cc149c18fd6d910a17.tar.bz2
Ishtar-8e002b956ea2b53d31a544cc149c18fd6d910a17.zip
Geo: clean old methods - fix geodata post treatments on geo form - quick add geo action
Diffstat (limited to 'ishtar_common/models_common.py')
-rw-r--r--ishtar_common/models_common.py64
1 files changed, 22 insertions, 42 deletions
diff --git a/ishtar_common/models_common.py b/ishtar_common/models_common.py
index a7dc8464e..1818c79f6 100644
--- a/ishtar_common/models_common.py
+++ b/ishtar_common/models_common.py
@@ -2470,12 +2470,6 @@ class GeoVectorData(Imported, OwnPerms):
return [round(x, rounded), round(y, rounded)]
return [x, y]
- def most_precise_geo(self):
- if self.multi_polygon:
- return "multi_polygon"
- if self.point_2d:
- return "point"
-
def _geojson_serialize(self, geom_attr):
if not hasattr(self, geom_attr):
return "{}"
@@ -2659,10 +2653,17 @@ def geodata_attached_changed(sender, **kwargs):
instance = kwargs.get("instance", None)
model = kwargs.get("model", None)
pk_set = kwargs.get("pk_set", None)
+
action = kwargs.get("action", None)
if not instance or not model:
return
+ if model != GeoVectorData: # reverse post attributes
+ instance_pk = instance.pk
+ instance = model.objects.get(pk=list(pk_set)[0])
+ model = GeoVectorData
+ pk_set = set([instance_pk])
+
if action == "post_add":
geodata_attached_post_add(model, instance, pk_set)
elif action == "post_remove":
@@ -2690,6 +2691,20 @@ class GeographicItem(models.Model):
class Meta:
abstract = True
+ def get_add_geo_action(self):
+ return (
+ reverse("create-pre-geo", args=[
+ self.__class__._meta.app_label,
+ self.__class__._meta.model_name,
+ self.pk
+ ]),
+ _("Add geographic item"),
+ "fa fa-plus",
+ _("geo."),
+ "",
+ False
+ )
+
def geodata_child_item_queries(self):
"""
:return: list of queries associated geographically with this item. When
@@ -3642,9 +3657,9 @@ class DynamicRequest:
class GeoItem(GeographicItem):
+ # gis - to be removed
GEO_SOURCE = (("T", _("Town")), ("P", _("Precise")), ("M", _("Polygon")))
- # gis
x = models.FloatField(_("X"), blank=True, null=True)
y = models.FloatField(_("Y"), blank=True, null=True)
z = models.FloatField(_("Z"), blank=True, null=True)
@@ -3756,41 +3771,6 @@ class GeoItem(GeographicItem):
return [round(x, 5), round(y, 5)]
return [x, y]
- def most_precise_geo(self):
- if self.point_source == "M":
- return "multi_polygon"
- current_source = str(self.__class__._meta.verbose_name)
- if self.multi_polygon_source_item == current_source and (
- self.multi_polygon_source == "P"
- or (self.point_source_item != current_source and self.point_source != "P")
- ):
- return "multi_polygon"
- if self.point_source_item == current_source and self.point_source == "P":
- return "point"
- if self.multi_polygon_source == "P":
- return "multi_polygon"
- if self.point_source == "P":
- return "point"
- if self.multi_polygon:
- return "multi_polygon"
- if self.point_2d:
- return "point"
-
- def geo_point_source(self):
- if not self.point_source:
- return ""
- return "{} - {}".format(
- dict(self.GEO_SOURCE)[self.point_source], self.point_source_item
- )
-
- def geo_polygon_source(self):
- if not self.multi_polygon_source:
- return ""
- return "{} - {}".format(
- dict(self.GEO_SOURCE)[self.multi_polygon_source],
- self.multi_polygon_source_item,
- )
-
def _geojson_serialize(self, geom_attr):
if not hasattr(self, geom_attr):
return ""