From 439d9438370006a6a08644164da286aa6133a110 Mon Sep 17 00:00:00 2001 From: mattiagiupponi <51856725+mattiagiupponi@users.noreply.github.com> Date: Thu, 25 Feb 2021 18:03:36 +0100 Subject: [PATCH] #42 add Positional Accuracy --- rndt/__init__.py | 2 +- rndt/layers/forms.py | 6 +++ rndt/layers/views.py | 47 +++++++++++----------- rndt/migrations/0005_layerrndt_accuracy.py | 18 +++++++++ rndt/models.py | 2 +- rndt/templates/layouts/panels.html | 20 ++++----- rndt/templates/xml/template-rndt.xml | 5 +-- rndt/templatetags/metadata_tags.py | 5 +++ rndt/templatetags/rndt_extra.py | 11 ++++- 9 files changed, 78 insertions(+), 38 deletions(-) create mode 100644 rndt/migrations/0005_layerrndt_accuracy.py diff --git a/rndt/__init__.py b/rndt/__init__.py index 70375b0..32e27ca 100644 --- a/rndt/__init__.py +++ b/rndt/__init__.py @@ -1,4 +1,4 @@ -VERSION = (0, 1, 11) +VERSION = (0, 1, 12) __version__ = ".".join([str(i) for i in VERSION]) __author__ = "geosolutions-it" __email__ = "info@geosolutionsgroup.com" diff --git a/rndt/layers/forms.py b/rndt/layers/forms.py index 9684320..4c7317b 100644 --- a/rndt/layers/forms.py +++ b/rndt/layers/forms.py @@ -32,6 +32,12 @@ class Meta: widget=NumberInput(attrs={"class": "form-control"}), ) + accuracy = forms.FloatField( + label=_("accuracy"), + required=False, + widget=NumberInput(attrs={"class": "form-control"}), + ) + def __init__(self, *args, **kwargs): super(LayerRNDTForm, self).__init__(*args, *kwargs) lang = get_language() diff --git a/rndt/layers/views.py b/rndt/layers/views.py index ba1b63d..67fc717 100644 --- a/rndt/layers/views.py +++ b/rndt/layers/views.py @@ -47,29 +47,30 @@ def layer_metadata( # get cleaned form values items = constraint_form.cleaned_data - if items["access_contraints"]: - # create the constraints_other required for RNDT - keyword = ThesaurusKeyword.objects.get(id=items['access_contraints']) - # get the layer available or create it - available = LayerRNDT.objects.filter(layer=layer) - # if the object does not exists, will save it for the first time - if not available.exists(): - available = LayerRNDT( - layer=layer, - constraints_other=keyword.about, - resolution=items["resolution"], - ) - # save the new value in the DB - available.save() - else: - # if the object exists and the constraing_other is changed - # the value will be updated - available = available.first() - if not available.is_equal(keyword.about): - available.constraints_other = keyword.about - available.resolution = items["resolution"] - # save the new value in the DB - available.save() + # create the constraints_other required for RNDT + keyword_id = items['access_contraints'] + keyword = ThesaurusKeyword.objects.get(id=keyword_id) if keyword_id else None + # get the layer available or create it + available = LayerRNDT.objects.filter(layer=layer) + # if the object does not exists, will save it for the first time + if not available.exists(): + available = LayerRNDT( + layer=layer, + constraints_other=keyword.about if keyword else None, + resolution=items["resolution"], + accuracy=items["accuracy"], + ) + # save the new value in the DB + available.save() + else: + # if the object exists and the constraing_other is changed + # the value will be updated + available = available.first() + available.constraints_other = keyword.about + available.resolution = items["resolution"] + available.accuracy = items["accuracy"] + # save the new value in the DB + available.save() # get the value to be saved in constraints_other layer_constraint = ( diff --git a/rndt/migrations/0005_layerrndt_accuracy.py b/rndt/migrations/0005_layerrndt_accuracy.py new file mode 100644 index 0000000..5433cb0 --- /dev/null +++ b/rndt/migrations/0005_layerrndt_accuracy.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2.16 on 2021-02-25 16:27 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('rndt', '0004_layerrndt_resolution'), + ] + + operations = [ + migrations.AddField( + model_name='layerrndt', + name='accuracy', + field=models.FloatField(default=None, null=True), + ), + ] diff --git a/rndt/models.py b/rndt/models.py index d968d67..d14dc32 100644 --- a/rndt/models.py +++ b/rndt/models.py @@ -2,7 +2,6 @@ from django.db.models import signals from django.db.models.signals import post_save from django.dispatch import receiver - from geonode.base.models import Link, resourcebase_post_save from geonode.groups.models import GroupProfile from geonode.layers.models import Layer, ResourceBase @@ -118,6 +117,7 @@ class LayerRNDT(models.Model): layer = models.OneToOneField(Layer, on_delete=models.CASCADE) constraints_other = models.TextField(default=None, null=True) resolution = models.FloatField(default=None, null=True) + accuracy = models.FloatField(default=None, null=True) def __str__(self): return f"{self.layer.title}: {self.constraints_other}" diff --git a/rndt/templates/layouts/panels.html b/rndt/templates/layouts/panels.html index 7132c3c..b8b00e0 100644 --- a/rndt/templates/layouts/panels.html +++ b/rndt/templates/layouts/panels.html @@ -132,17 +132,19 @@
-
-
{% trans "Resolution" %}
-
-
-
-
mt
- {{ LayerRNDTForm.resolution|get_resolution_value:layer.id }} -
-
+
+
+
+
mt
+ {{ LayerRNDTForm.resolution|get_resolution_value:layer.id }} +
+
+
+
mt
+ {{ LayerRNDTForm.accuracy|get_accuracy_value:layer.id }}
+
{% endblock other_tab %} diff --git a/rndt/templates/xml/template-rndt.xml b/rndt/templates/xml/template-rndt.xml index 342b70f..10a2c4a 100644 --- a/rndt/templates/xml/template-rndt.xml +++ b/rndt/templates/xml/template-rndt.xml @@ -365,7 +365,7 @@ {% if keyword.thesaurus.id == thesaurus_id %} {{keyword|get_keyword_label}} + xlink:href="{{keyword.about}}">{{keyword.alt_label}} {% endif %} {% endfor %} @@ -747,8 +747,7 @@ - {# TODO #} - 1.0 + {{layer.id|get_positional_accuracy}} diff --git a/rndt/templatetags/metadata_tags.py b/rndt/templatetags/metadata_tags.py index f13fca1..2db8f97 100644 --- a/rndt/templatetags/metadata_tags.py +++ b/rndt/templatetags/metadata_tags.py @@ -41,3 +41,8 @@ def is_url(item): return True except: return False + + +@register.filter +def get_positional_accuracy(layer_id): + return LayerRNDT.objects.get(layer_id=layer_id).accuracy diff --git a/rndt/templatetags/rndt_extra.py b/rndt/templatetags/rndt_extra.py index 9ecbf38..fa05807 100644 --- a/rndt/templatetags/rndt_extra.py +++ b/rndt/templatetags/rndt_extra.py @@ -29,8 +29,17 @@ def get_other_constraint(constraint_id, layer_id): @register.filter def get_resolution_value(value, layer_id): + return get_numeric(value, layer_id, "resolution") + + +@register.filter +def get_accuracy_value(value, layer_id): + return get_numeric(value, layer_id, "accuracy") + + +def get_numeric(value, layer_id, category): layer = LayerRNDT.objects.filter(layer=layer_id) if layer.exists(): - value.initial = layer.get().resolution + value.initial = getattr(layer.get(), category) return value return value