5c0b1c412d
* fixes created timestamp in detail views where modified needs to be displayed * adds fallback timestamp if data has not been edited, yet --> show created timestamp * fixes bug where deleting of certain data didn't redirect to the index view * adds quality_check() method for EMA, needed for recording * adds all functions which are provided for compensations to EMA * adds/updates translations
86 lines
2.8 KiB
Python
86 lines
2.8 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,
|
|
)
|
|
|
|
def quality_check(self) -> list:
|
|
""" Quality check
|
|
|
|
Returns:
|
|
ret_msgs (list): Holds error messages
|
|
"""
|
|
ret_msgs = []
|
|
|
|
# ToDo: Add check methods!
|
|
|
|
return ret_msgs |