LANIS Link

* adds LANIS link getter to Intervention, Compensation and EcoAccount for creating a usable link to LANIS
* adds/updates translations
This commit is contained in:
mipel
2021-08-10 13:57:03 +02:00
parent 07a428d0e5
commit c165e3f990
11 changed files with 84 additions and 8 deletions

View File

@@ -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):
"""

View File

@@ -1,7 +1,7 @@
{% load i18n l10n fontawesome_5 %}
<div class="d-flex justify-content-end">
<a href="{% url 'home' %}" class="mr-2">
<a href="{{LANIS_LINK}}" class="mr-2" target="_blank">
<button class="btn btn-default" title="{% trans 'Open in LANIS' %}">
LANIS
</button>

View File

@@ -1,7 +1,7 @@
{% load i18n l10n fontawesome_5 %}
<div class="d-flex justify-content-end">
<a href="{% url 'home' %}" class="mr-2">
<a href="{{LANIS_LINK}}" class="mr-2" target="_blank">
<button class="btn btn-default" title="{% trans 'Open in LANIS' %}">
LANIS
</button>

View File

@@ -95,6 +95,7 @@ def open_view(request: HttpRequest, id: str):
"is_default_member": in_group(_user, DEFAULT_GROUP),
"is_zb_member": in_group(_user, ZB_GROUP),
"is_ets_member": in_group(_user, ETS_GROUP),
"LANIS_LINK": comp.get_LANIS_link(),
}
context = BaseContext(request, context).context
return render(request, template, context)

View File

@@ -111,6 +111,7 @@ def open_view(request: HttpRequest, id: str):
"is_default_member": in_group(_user, DEFAULT_GROUP),
"is_zb_member": in_group(_user, ZB_GROUP),
"is_ets_member": in_group(_user, ETS_GROUP),
"LANIS_LINK": acc.get_LANIS_link(),
}
context = BaseContext(request, context).context
return render(request, template, context)