summaryrefslogtreecommitdiff
path: root/ishtar_common
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2022-03-15 17:05:43 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2022-12-12 12:21:00 +0100
commit222dac8bce00300a26c8aa7bba99ae7160723946 (patch)
tree1e48546125087a3b16ff9afcae784461d7f51a97 /ishtar_common
parentb36bd54a551eedb1129e60c3edc558591d417b9a (diff)
downloadIshtar-222dac8bce00300a26c8aa7bba99ae7160723946.tar.bz2
Ishtar-222dac8bce00300a26c8aa7bba99ae7160723946.zip
Geodata: fix search display
Diffstat (limited to 'ishtar_common')
-rw-r--r--ishtar_common/models_common.py12
-rw-r--r--ishtar_common/utils.py4
-rw-r--r--ishtar_common/views_item.py34
3 files changed, 26 insertions, 24 deletions
diff --git a/ishtar_common/models_common.py b/ishtar_common/models_common.py
index a7f9bd2fd..414e63c55 100644
--- a/ishtar_common/models_common.py
+++ b/ishtar_common/models_common.py
@@ -2132,11 +2132,13 @@ class GeoVectorData(models.Model):
name += f" ({str(self.data_type).lower()})"
return name
- def display_coordinates(self, rounded=5, dim=2, cache=True):
- srid = None
- profile = get_current_profile()
- if profile.display_srs and profile.display_srs.srid:
- srid = profile.display_srs.srid
+ def display_coordinates(self, rounded=5, dim=2, srid=4326, cache=True):
+ if not srid:
+ profile = get_current_profile()
+ if profile.display_srs and profile.display_srs.srid:
+ srid = profile.display_srs.srid
+ else:
+ srid = 4326
return self.get_coordinates(rounded=rounded, srid=srid, dim=dim, cache=cache)
def get_coordinates(self, rounded=5, srid: int = None, dim=2, cache=False):
diff --git a/ishtar_common/utils.py b/ishtar_common/utils.py
index 88c9129a3..89700eaad 100644
--- a/ishtar_common/utils.py
+++ b/ishtar_common/utils.py
@@ -776,11 +776,11 @@ def _post_save_geodata(sender, **kwargs):
# managed cached coordinates
cached_x, cached_y, cached_z = None, None, None
- coords = instance.display_coordinates(rounded=False, dim=3, cache=False)
+ coords = instance.display_coordinates(rounded=False, dim=3, srid=4326, cache=False)
if coords and coords != [None, None, None]:
cached_x, cached_y, cached_z = coords
else:
- coords = instance.display_coordinates(rounded=False, dim=2, cache=False)
+ coords = instance.display_coordinates(rounded=False, dim=2, srid=4326, cache=False)
if coords:
cached_x, cached_y = coords
diff --git a/ishtar_common/views_item.py b/ishtar_common/views_item.py
index 404df6f90..68a340a75 100644
--- a/ishtar_common/views_item.py
+++ b/ishtar_common/views_item.py
@@ -20,6 +20,7 @@ from django.contrib.staticfiles.templatetags.staticfiles import static
from django.core.cache import cache
from django.core.exceptions import ObjectDoesNotExist
from django.db.models import (
+ F,
Q,
Count,
Sum,
@@ -1361,7 +1362,8 @@ def _format_geojson(rows, link_template):
return data
-def _get_data_from_query(items, query_table_cols, extra_request_keys, point_field=None):
+def _get_data_from_query(items, query_table_cols, extra_request_keys,
+ point_fields=None):
# TODO: manage data json field
for query_keys in query_table_cols:
if not isinstance(query_keys, (tuple, list)):
@@ -1379,25 +1381,21 @@ def _get_data_from_query(items, query_table_cols, extra_request_keys, point_fiel
query_key.replace(".", "__") # class style to query
values = ["id"] + query_table_cols
- if point_field:
+ if point_fields:
profile = get_current_profile()
precision = profile.point_precision
if precision is not None:
exp_x = ExpressionWrapper(
- Round(Func(point_field, function="ST_X"), precision),
+ Round(point_fields[0], precision),
output_field=FloatField(),
)
exp_y = ExpressionWrapper(
- Round(Func(point_field, function="ST_Y"), precision),
+ Round(point_fields[1], precision),
output_field=FloatField(),
)
else:
- exp_x = ExpressionWrapper(
- Func(point_field, function="ST_X"), output_field=FloatField()
- )
- exp_y = ExpressionWrapper(
- Func(point_field, function="ST_Y"), output_field=FloatField()
- )
+ exp_x = F(point_fields[0])
+ exp_y = F(point_fields[1])
items = items.annotate(point_x=exp_x)
items = items.annotate(point_y=exp_y)
values += ["point_x", "point_y"]
@@ -2100,12 +2098,13 @@ def get_item(
query_table_cols.append("main_image__image")
table_cols.append("main_image__image")
elif data_type == "json-map":
+ base_query_key = "main_geodata__"
if model.SLUG == "find":
- query_table_cols.append("base_finds__point_2d")
- table_cols.append("base_finds__point_2d")
- else:
- query_table_cols.append("point_2d")
- table_cols.append("point_2d")
+ base_query_key = "base_finds__" + base_query_key
+ query_table_cols += [base_query_key + "cached_x",
+ base_query_key + "cached_y"]
+ table_cols += [base_query_key + "cached_x",
+ base_query_key + "cached_y"]
# manage sort tables
manual_sort_key = None
@@ -2195,9 +2194,10 @@ def get_item(
items = [item.get_previous(old) for item in items]
if data_type == "json-map":
- point_field = query_table_cols.pop()
+ point_fields = query_table_cols[-2:]
datas = _get_data_from_query(
- items, query_table_cols, my_extra_request_keys, point_field=point_field
+ items, query_table_cols, my_extra_request_keys,
+ point_fields=point_fields
)
elif data_type != "csv" and getattr(model, "NEW_QUERY_ENGINE", False):
datas = _get_data_from_query(items, query_table_cols, my_extra_request_keys)