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 @@