You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
konova/ema/models.py

75 lines
2.6 KiB
Python

from django.contrib.auth.models import User
from django.db import models
from compensation.models import AbstractCompensation
from konova.settings import DEFAULT_SRID_RLP, LANIS_LINK_TEMPLATE
from user.models import UserActionLogEntry
class Ema(AbstractCompensation):
"""
EMA = Ersatzzahlungsmaßnahme
(compensation actions from payments)
Until 2015 the EMA was the data object to keep track of any compensation, which has been funded by payments
previously paid. In 2015 another organization got in charge of this, which led to the creation of the data object
MAE (which is basically the same, just renamed in their system) to differ between the 'old' payment funded ones and
the new. For historical reasons, we need to keep EMAs in our system, since there are still entries done to this day,
which have been performed somewhere before 2015 and therefore needs to be entered.
Further information:
https://snu.rlp.de/de/foerderungen/massnahmen-aus-ersatzzahlungen/uebersicht-mae/
EMA therefore holds data like a compensation: actions, before-/after-states, deadlines, ...
"""
# Users having access on this object
# Not needed in regular Compensation since their access is defined by the linked intervention's access
users = models.ManyToManyField(
User,
help_text="Users having access (shared with)"
)
# Refers to "verzeichnen"
recorded = models.OneToOneField(
UserActionLogEntry,
on_delete=models.SET_NULL,
null=True,
blank=True,
help_text="Holds data on user and timestamp of this action",
related_name="+"
)
def __str__(self):
return "{}".format(self.identifier)
def save(self, *args, **kwargs):
if self.identifier is None or len(self.identifier) == 0:
# Create new identifier
new_id = self._generate_new_identifier()
while Ema.objects.filter(identifier=new_id).exists():
new_id = self._generate_new_identifier()
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,
)