diff --git a/compensation/models.py b/compensation/models.py index 8c45bcf6..8e0dde35 100644 --- a/compensation/models.py +++ b/compensation/models.py @@ -15,6 +15,7 @@ from django.utils.translation import gettext_lazy as _ from compensation.settings import COMPENSATION_IDENTIFIER_LENGTH, COMPENSATION_IDENTIFIER_TEMPLATE from intervention.models import Intervention, ResponsibilityData from konova.models import BaseObject, BaseResource, Geometry, UuidModel +from konova.settings import DEFAULT_SRID_RLP, LANIS_LINK_TEMPLATE from konova.utils.generators import generate_random_string from user.models import UserActionLogEntry @@ -169,6 +170,28 @@ class Compensation(AbstractCompensation): self.identifier = new_id super().save(*args, **kwargs) + def get_LANIS_link(self) -> str: + """ Generates a link for LANIS depending on the geometry + + Returns: + + """ + try: + geom = self.geometry.geom.transform(DEFAULT_SRID_RLP, clone=True) + x = geom.centroid.x + y = geom.centroid.y + zoom_lvl = 16 + except AttributeError: + # If no geometry has been added, yet. + x = 1 + y = 1 + zoom_lvl = 6 + return LANIS_LINK_TEMPLATE.format( + zoom_lvl, + x, + y, + ) + class EcoAccount(AbstractCompensation): """ @@ -203,6 +226,28 @@ class EcoAccount(AbstractCompensation): """ return self.withdraws.all().aggregate(Sum("surface"))["surface__sum"] + def get_LANIS_link(self) -> str: + """ Generates a link for LANIS depending on the geometry + + Returns: + + """ + try: + geom = self.geometry.geom.transform(DEFAULT_SRID_RLP, clone=True) + x = geom.centroid.x + y = geom.centroid.y + zoom_lvl = 16 + except AttributeError: + # If no geometry has been added, yet. + x = 1 + y = 1 + zoom_lvl = 6 + return LANIS_LINK_TEMPLATE.format( + zoom_lvl, + x, + y, + ) + class EcoAccountWithdraw(BaseResource): """ diff --git a/compensation/templates/compensation/detail/compensation/includes/controls.html b/compensation/templates/compensation/detail/compensation/includes/controls.html index 34a5c031..0f5149a5 100644 --- a/compensation/templates/compensation/detail/compensation/includes/controls.html +++ b/compensation/templates/compensation/detail/compensation/includes/controls.html @@ -1,7 +1,7 @@ {% load i18n l10n fontawesome_5 %}