diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-07-03 12:46:51 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-07-03 12:46:51 +0200 |
commit | 9387d122749bf22477145b367683708a7cca10d9 (patch) | |
tree | 16205f1739d6fabf45fd9ea41e221e0a8dc1d6af | |
parent | 5be5e1fb11a3c14fda29d2e623ee55c6d08b509c (diff) | |
download | Ishtar-9387d122749bf22477145b367683708a7cca10d9.tar.bz2 Ishtar-9387d122749bf22477145b367683708a7cca10d9.zip |
Geo search and sheets: add a point precision for display
m--------- | drassm_app | 0 | ||||
-rw-r--r-- | ishtar_common/migrations/0098_ishtarsiteprofile_point_precision.py | 20 | ||||
-rw-r--r-- | ishtar_common/models.py | 17 | ||||
-rw-r--r-- | ishtar_common/utils.py | 6 | ||||
-rw-r--r-- | ishtar_common/views_item.py | 22 |
5 files changed, 58 insertions, 7 deletions
diff --git a/drassm_app b/drassm_app deleted file mode 160000 -Subproject 7aff87e1aa0c05e42d160d1a222c64a3c6270d1 diff --git a/ishtar_common/migrations/0098_ishtarsiteprofile_point_precision.py b/ishtar_common/migrations/0098_ishtarsiteprofile_point_precision.py new file mode 100644 index 000000000..f7f731da8 --- /dev/null +++ b/ishtar_common/migrations/0098_ishtarsiteprofile_point_precision.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.18 on 2019-07-03 12:35 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('ishtar_common', '0097_auto_20190628_1256'), + ] + + operations = [ + migrations.AddField( + model_name='ishtarsiteprofile', + name='point_precision', + field=models.IntegerField(blank=True, help_text='Number of digit to round from the decimal point for coordinates in WGS84 (latitude, longitude). Empty value means no round.', null=True, verbose_name='Point precision (search and sheets)'), + ), + ] diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 93a099b74..5e7f6e9b3 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -1899,12 +1899,22 @@ class GeoItem(models.Model): self.__class__.objects.filter(pk=self.pk), geometry_field=geom_attr, fields=(cached_label_key,)) geojson_dct = json.loads(geojson) + profile = get_current_profile() + precision = profile.point_precision + features = geojson_dct.pop('features') for idx in range(len(features)): feature = features[idx] lbl = feature['properties'].pop(cached_label_key) feature['properties']['name'] = lbl feature['properties']['id'] = self.pk + if precision is not None: + geom_type = feature["geometry"].get("type", None) + if geom_type == "Point": + feature["geometry"]["coordinates"] = [ + round(coord, precision) + for coord in feature["geometry"]["coordinates"] + ] geojson_dct['features'] = features geojson_dct['link_template'] = simple_link_to_window(self).replace( '999999', '<pk>' @@ -2575,6 +2585,13 @@ class IshtarSiteProfile(models.Model, Cached): preservation = models.BooleanField(_("Preservation module"), default=False) mapping = models.BooleanField(_("Mapping module"), default=False) + point_precision = models.IntegerField( + _("Point precision (search and sheets)"), null=True, blank=True, + help_text=_( + "Number of digit to round from the decimal point for coordinates " + "in WGS84 (latitude, longitude). Empty value means no round." + ) + ) locate_warehouses = models.BooleanField( _("Locate warehouse and containers"), default=False, help_text=_( diff --git a/ishtar_common/utils.py b/ishtar_common/utils.py index f3df5c282..83bc56279 100644 --- a/ishtar_common/utils.py +++ b/ishtar_common/utils.py @@ -97,6 +97,12 @@ class BColors: UNDERLINE = '\033[4m' +class Round(models.Func): + function = 'ROUND' + arity = 2 + arg_joiner = '::numeric, ' + + CSV_OPTIONS = {'delimiter': ',', 'quotechar': '"', 'quoting': QUOTE_ALL} diff --git a/ishtar_common/views_item.py b/ishtar_common/views_item.py index 0b0c61b86..799292969 100644 --- a/ishtar_common/views_item.py +++ b/ishtar_common/views_item.py @@ -32,7 +32,7 @@ from weasyprint import HTML, CSS from weasyprint.fonts import FontConfiguration from ishtar_common.utils import check_model_access_control, CSV_OPTIONS, \ - get_all_field_names + get_all_field_names, Round from ishtar_common.models import HistoryError, get_current_profile, \ PRIVATE_FIELDS, GeneralType, SearchAltName from .menus import Menu @@ -1124,14 +1124,22 @@ def _get_data_from_query(items, query_table_cols, extra_request_keys, values = ['id'] + query_table_cols if point_field: - items = items.annotate( - point_x=ExpressionWrapper( + profile = get_current_profile() + precision = profile.point_precision + if precision is not None: + exp_x = ExpressionWrapper( + Round(Func(point_field, function='ST_X'), precision), + output_field=FloatField()) + exp_y = ExpressionWrapper( + Round(Func(point_field, function='ST_Y'), precision), + output_field=FloatField()) + else: + exp_x = ExpressionWrapper( Func(point_field, function='ST_X'), output_field=FloatField()) - ) - items = items.annotate( - point_y=ExpressionWrapper( + exp_y = ExpressionWrapper( Func(point_field, function='ST_Y'), output_field=FloatField()) - ) + items = items.annotate(point_x=exp_x) + items = items.annotate(point_y=exp_y) values += ['point_x', 'point_y'] data_list = items.values_list(*values) return data_list |