From 274d7b8b6ff5f1dd8f8c1d87e0396681117e4fca Mon Sep 17 00:00:00 2001 From: mpeltriaux Date: Wed, 25 Oct 2023 10:04:56 +0200 Subject: [PATCH] # 349 LANIS link improvements * replaces 'dumb' link template with LANIS mapinterface support * adds fallback default LANIS link --- compensation/models/compensation.py | 22 +++++++++++++++- compensation/models/eco_account.py | 18 ++++++++++--- compensation/settings.py | 7 ++++- ema/models/ema.py | 17 +++++++++++- ema/settings.py | 4 ++- intervention/models/intervention.py | 25 +++++++++++++++++- intervention/settings.py | 4 +++ konova/models/object.py | 37 ++++++++++----------------- konova/sub_settings/lanis_settings.py | 3 ++- 9 files changed, 105 insertions(+), 32 deletions(-) diff --git a/compensation/models/compensation.py b/compensation/models/compensation.py index a32926c..85ec73b 100644 --- a/compensation/models/compensation.py +++ b/compensation/models/compensation.py @@ -9,8 +9,10 @@ import shutil from django.contrib import messages +from analysis.settings import LKOMPVZVO_PUBLISH_DATE from codelist.models import KonovaCode -from compensation.settings import COMPENSATION_IDENTIFIER_TEMPLATE, COMPENSATION_IDENTIFIER_LENGTH +from compensation.settings import COMPENSATION_IDENTIFIER_TEMPLATE, COMPENSATION_IDENTIFIER_LENGTH, \ + COMPENSATION_LANIS_LAYER_NAME_RECORDED, COMPENSATION_LANIS_LAYER_NAME_UNRECORDED, COMPENSATION_LANIS_LAYER_NAME_UNRECORDED_OLD_ENTRY from user.models import User, Team from django.db import models, transaction from django.db.models import QuerySet, Sum @@ -478,6 +480,24 @@ class Compensation(AbstractCompensation, CEFMixin, CoherenceMixin, PikMixin): """ return self.intervention.is_recorded + def get_lanis_layer_name(self): + """ Getter for specific LANIS/WFS object layer + + Returns: + + """ + retval = None + if self.is_recorded: + retval = COMPENSATION_LANIS_LAYER_NAME_RECORDED + else: + is_old_entry = self.intervention.legal.binding_date < LKOMPVZVO_PUBLISH_DATE + if is_old_entry: + retval = COMPENSATION_LANIS_LAYER_NAME_UNRECORDED_OLD_ENTRY + else: + retval = COMPENSATION_LANIS_LAYER_NAME_UNRECORDED + + return retval + class CompensationDocument(AbstractDocument): """ diff --git a/compensation/models/eco_account.py b/compensation/models/eco_account.py index fc65e50..afebfbe 100644 --- a/compensation/models/eco_account.py +++ b/compensation/models/eco_account.py @@ -9,13 +9,12 @@ import shutil from django.urls import reverse -from compensation.settings import ECO_ACCOUNT_IDENTIFIER_TEMPLATE, ECO_ACCOUNT_IDENTIFIER_LENGTH +from compensation.settings import ECO_ACCOUNT_IDENTIFIER_TEMPLATE, ECO_ACCOUNT_IDENTIFIER_LENGTH, \ + ECO_ACCOUNT_LANIS_LAYER_NAME_RECORDED, ECO_ACCOUNT_LANIS_LAYER_NAME_UNRECORDED from konova.utils.message_templates import DEDUCTION_REMOVED, DOCUMENT_REMOVED_TEMPLATE -from django.core.exceptions import ValidationError from django.core.validators import MinValueValidator from django.db import models from django.db.models import Sum, QuerySet -from django.utils.translation import gettext_lazy as _ from compensation.managers import EcoAccountManager, EcoAccountDeductionManager from compensation.models.compensation import AbstractCompensation, PikMixin @@ -192,6 +191,19 @@ class EcoAccount(AbstractCompensation, ShareableObjectMixin, RecordableObjectMix ret_val = 0 return ret_val + def get_lanis_layer_name(self): + """ Getter for specific LANIS/WFS object layer + + Returns: + + """ + retval = None + if self.is_recorded: + retval = ECO_ACCOUNT_LANIS_LAYER_NAME_RECORDED + else: + retval = ECO_ACCOUNT_LANIS_LAYER_NAME_UNRECORDED + + return retval class EcoAccountDocument(AbstractDocument): """ diff --git a/compensation/settings.py b/compensation/settings.py index 2ac5464..00a2357 100644 --- a/compensation/settings.py +++ b/compensation/settings.py @@ -7,6 +7,11 @@ Created on: 18.12.20 """ COMPENSATION_IDENTIFIER_LENGTH = 6 COMPENSATION_IDENTIFIER_TEMPLATE = "KOM-{}" +COMPENSATION_LANIS_LAYER_NAME_RECORDED = "kom_recorded" +COMPENSATION_LANIS_LAYER_NAME_UNRECORDED = "kom_unrecorded" +COMPENSATION_LANIS_LAYER_NAME_UNRECORDED_OLD_ENTRY = "kom_unrecorded_old_entries" ECO_ACCOUNT_IDENTIFIER_LENGTH = 6 -ECO_ACCOUNT_IDENTIFIER_TEMPLATE = "OEK-{}" \ No newline at end of file +ECO_ACCOUNT_IDENTIFIER_TEMPLATE = "OEK-{}" +ECO_ACCOUNT_LANIS_LAYER_NAME_RECORDED = "oek_recorded" +ECO_ACCOUNT_LANIS_LAYER_NAME_UNRECORDED = "oek_unrecorded" \ No newline at end of file diff --git a/ema/models/ema.py b/ema/models/ema.py index 5e380ee..d312c6a 100644 --- a/ema/models/ema.py +++ b/ema/models/ema.py @@ -15,7 +15,8 @@ from django.urls import reverse from compensation.models import AbstractCompensation, PikMixin from ema.managers import EmaManager -from ema.settings import EMA_IDENTIFIER_LENGTH, EMA_IDENTIFIER_TEMPLATE +from ema.settings import EMA_IDENTIFIER_LENGTH, EMA_IDENTIFIER_TEMPLATE, EMA_LANIS_LAYER_NAME_RECORDED, \ + EMA_LANIS_LAYER_NAME_UNRECORDED from ema.utils.quality import EmaQualityChecker from konova.models import AbstractDocument, generate_document_file_upload_path, RecordableObjectMixin, ShareableObjectMixin from konova.utils.message_templates import DATA_UNSHARED_EXPLANATION, DOCUMENT_REMOVED_TEMPLATE @@ -109,6 +110,20 @@ class Ema(AbstractCompensation, ShareableObjectMixin, RecordableObjectMixin, Pik """ return reverse("ema:share-token", args=(self.id, self.access_token)) + def get_lanis_layer_name(self): + """ Getter for specific LANIS/WFS object layer + + Returns: + + """ + retval = None + if self.is_recorded: + retval = EMA_LANIS_LAYER_NAME_RECORDED + else: + retval = EMA_LANIS_LAYER_NAME_UNRECORDED + + return retval + class EmaDocument(AbstractDocument): """ diff --git a/ema/settings.py b/ema/settings.py index a6a124c..357f96d 100644 --- a/ema/settings.py +++ b/ema/settings.py @@ -7,4 +7,6 @@ Created on: 19.08.21 """ EMA_IDENTIFIER_LENGTH = 6 -EMA_IDENTIFIER_TEMPLATE = "EMA-{}" \ No newline at end of file +EMA_IDENTIFIER_TEMPLATE = "EMA-{}" +EMA_LANIS_LAYER_NAME_RECORDED = "ema_recorded" +EMA_LANIS_LAYER_NAME_UNRECORDED = "ema_unrecorded" \ No newline at end of file diff --git a/intervention/models/intervention.py b/intervention/models/intervention.py index d54a1b9..25779c3 100644 --- a/intervention/models/intervention.py +++ b/intervention/models/intervention.py @@ -14,7 +14,9 @@ from django.urls import reverse from django.utils import timezone from analysis.settings import LKOMPVZVO_PUBLISH_DATE -from intervention.settings import INTERVENTION_IDENTIFIER_LENGTH, INTERVENTION_IDENTIFIER_TEMPLATE +from intervention.settings import INTERVENTION_IDENTIFIER_LENGTH, INTERVENTION_IDENTIFIER_TEMPLATE, \ + INTERVENTION_LANIS_LAYER_NAME_RECORDED, INTERVENTION_LANIS_LAYER_NAME_UNRECORDED_OLD_ENTRY, \ + INTERVENTION_LANIS_LAYER_NAME_UNRECORDED from intervention.tasks import celery_export_to_egon from user.models import User from django.db import models, transaction @@ -383,6 +385,27 @@ class Intervention(BaseObject, self.mark_as_edited(user, request=form.request, edit_comment=PAYMENT_REMOVED) self.send_data_to_egon() + def get_lanis_layer_name(self): + """ Getter for specific LANIS/WFS object layer + + Returns: + + """ + retval = None + if self.is_recorded: + retval = INTERVENTION_LANIS_LAYER_NAME_RECORDED + else: + try: + is_old_entry = self.legal.binding_date < LKOMPVZVO_PUBLISH_DATE + except TypeError: + is_old_entry = True + if is_old_entry: + retval = INTERVENTION_LANIS_LAYER_NAME_UNRECORDED_OLD_ENTRY + else: + retval = INTERVENTION_LANIS_LAYER_NAME_UNRECORDED + + return retval + class InterventionDocument(AbstractDocument): """ diff --git a/intervention/settings.py b/intervention/settings.py index a5c974d..8d3d624 100644 --- a/intervention/settings.py +++ b/intervention/settings.py @@ -8,6 +8,10 @@ Created on: 30.11.20 INTERVENTION_IDENTIFIER_LENGTH = 6 INTERVENTION_IDENTIFIER_TEMPLATE = "EIV-{}" +INTERVENTION_LANIS_LAYER_NAME_RECORDED = "eiv_recorded" +INTERVENTION_LANIS_LAYER_NAME_UNRECORDED = "eiv_unrecorded" +INTERVENTION_LANIS_LAYER_NAME_UNRECORDED_OLD_ENTRY = "eiv_unrecorded_old_entries" + # EGON connection settings via rabbitmq # NEEDED FOR BACKWARDS COMPATIBILITY EGON_RABBITMQ_HOST = "CHANGE_ME" diff --git a/konova/models/object.py b/konova/models/object.py index 038b47f..c7eb15c 100644 --- a/konova/models/object.py +++ b/konova/models/object.py @@ -12,7 +12,7 @@ from abc import abstractmethod from django.contrib import messages from django.db.models import QuerySet -from konova.sub_settings.lanis_settings import DEFAULT_SRID_RLP, LANIS_ZOOM_LUT, LANIS_LINK_TEMPLATE +from konova.sub_settings.lanis_settings import LANIS_LINK_TEMPLATE, LANIS_LINK_DEFAULT from konova.tasks import celery_send_mail_shared_access_removed, celery_send_mail_shared_access_given, \ celery_send_mail_shared_data_recorded, celery_send_mail_shared_data_unrecorded, \ celery_send_mail_shared_data_deleted, celery_send_mail_shared_data_checked, \ @@ -706,32 +706,23 @@ class GeoReferencedMixin(models.Model): return request def get_LANIS_link(self) -> str: - """ Generates a link for LANIS depending on the geometry + """ Creates the link for 'LANIS' button on detail view of an entry. Returns: """ - try: - geom = self.geometry.geom.transform(DEFAULT_SRID_RLP, clone=True) - x = geom.centroid.x - y = geom.centroid.y - area = int(geom.envelope.area) - z_l = 16 - for k_area, v_zoom in LANIS_ZOOM_LUT.items(): - if k_area < area: - z_l = v_zoom - break - zoom_lvl = z_l - except (AttributeError, IndexError) as e: - # If no geometry has been added, yet. - x = 1 - y = 1 - zoom_lvl = 6 - return LANIS_LINK_TEMPLATE.format( - zoom_lvl, - x, - y, - ) + entry_has_geometry = not self.geometry.geom.empty + if entry_has_geometry: + link = LANIS_LINK_TEMPLATE.format( + self.get_lanis_layer_name(), + self.identifier + ) + else: + link = LANIS_LINK_DEFAULT + return link + + def get_lanis_layer_name(self): + raise NotImplementedError("Must be implemented in subclasses!") class ResubmitableObjectMixin(models.Model): diff --git a/konova/sub_settings/lanis_settings.py b/konova/sub_settings/lanis_settings.py index 58a2856..7208293 100644 --- a/konova/sub_settings/lanis_settings.py +++ b/konova/sub_settings/lanis_settings.py @@ -15,7 +15,8 @@ DEFAULT_SRID_RLP = 25832 # Needed to redirect to LANIS ## Values to be inserted are [zoom_level, x_coord, y_coord] -LANIS_LINK_TEMPLATE = "https://geodaten.naturschutz.rlp.de/kartendienste_naturschutz/index.php?lang=de&zl={}&x={}&y={}&bl=tk_rlp_tms_grau&bo=1&lo=0.8,0.8,0.8,0.6,0.8,0.8,0.8,0.8,0.8&layers=eiv_recorded,eiv_unrecorded,eiv_unrecorded_old_entries,kom_recorded,kom_unrecorded,kom_unrecorded_old_entries,oek_recorded,oek_unrecorded,ema_recorded,ema_unrecorded,mae&service=kartendienste_naturschutz" +LANIS_LINK_DEFAULT = "https://geodaten.naturschutz.rlp.de/kartendienste_naturschutz/index.php?lang=de&zl=7&x=378800&y=5535500&bl=tk_rlp_tms_grau&bo=1&lo=1,0.7,0.7,0.5,0.7,0.7,0.5,0.7,0.7,0.8,0.7,0.7&layers=grenzen_land,eiv_recorded,eiv_unrecorded,eiv_unrecorded_old_entries,kom_recorded,kom_unrecorded,kom_unrecorded_old_entries,ema_recorded,ema_unrecorded,mae,oek_recorded,oek_unrecorded&service=kartendienste_naturschutz" +LANIS_LINK_TEMPLATE = "https://geodaten.naturschutz.rlp.de/kartendienste_naturschutz/mapinterface.php?qlayer={}&qfield=identifier&qidtyp=text&qid={}&client=&layers=eiv_recorded,eiv_unrecorded,eiv_unrecorded_old_entries,kom_recorded,kom_unrecorded,kom_unrecorded_old_entries,oek_recorded,oek_unrecorded,ema_recorded,ema_unrecorded,mae&zoomobject=true" ## This look up table (LUT) defines different zoom levels on the size of the calculate area of a geometry. LANIS_ZOOM_LUT = { 1000000000: 6,