EMA
* adds Ema model (basically Compensation inherited) * adds index view for EMAs * fixes drop-down link bug for menu 'More' in navbar * refactors some more forms to use process_request() * adds modified attribute to BaseResource for easy last_modified check * adds setting of modified attribute in all places where UserAction.EDITED is added to log * adds EMA_ACCOUNT_IDENTIFIER_LENGTH and EMA_ACCOUNT_IDENTIFIER_TEMPLATE to ema/settings.py * adds EmaAdmin to ema/admin.py * fixes wrong title in intervention detail view html for revocations * adds support for subtitle variable to BaseTable and generic_index.html * drops next_version attribute from models * adds/updates translations * adds default ordering for UserActionLogEntry * removes extra ordering in log modal rendering
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
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,
|
||||
)
|
||||
Reference in New Issue
Block a user