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:
@@ -89,6 +89,8 @@ class NewPaymentForm(BaseModalForm):
|
||||
intervention=self.intervention,
|
||||
)
|
||||
self.intervention.log.add(edited_action)
|
||||
self.intervention.modified = edited_action
|
||||
self.intervention.save()
|
||||
return pay
|
||||
|
||||
|
||||
@@ -122,6 +124,8 @@ class NewStateModalForm(BaseModalForm):
|
||||
comment=_("Added state")
|
||||
)
|
||||
self.instance.log.add(user_action)
|
||||
self.instance.modified = user_action
|
||||
self.instance.save()
|
||||
|
||||
state = CompensationState.objects.create(
|
||||
biotope_type=self.cleaned_data["biotope_type"],
|
||||
@@ -244,6 +248,8 @@ class NewDeadlineModalForm(BaseModalForm):
|
||||
action=UserAction.EDITED,
|
||||
comment=_("Added deadline")
|
||||
)
|
||||
self.instance.modified = edited_action
|
||||
self.instance.save()
|
||||
self.instance.log.add(edited_action)
|
||||
self.instance.deadlines.add(deadline)
|
||||
return deadline
|
||||
@@ -314,6 +320,8 @@ class NewActionModalForm(BaseModalForm):
|
||||
action=UserAction.EDITED,
|
||||
comment=_("Added action"),
|
||||
)
|
||||
self.instance.modified = edited_action
|
||||
self.instance.save()
|
||||
self.instance.log.add(edited_action)
|
||||
self.instance.actions.add(comp_action)
|
||||
return comp_action
|
||||
|
||||
@@ -91,8 +91,8 @@ class CompensationAction(BaseResource):
|
||||
|
||||
class AbstractCompensation(BaseObject):
|
||||
"""
|
||||
Abstract compensation model which holds basic attributes, shared by subclasses like the regular Compensation
|
||||
or EcoAccount.
|
||||
Abstract compensation model which holds basic attributes, shared by subclasses like the regular Compensation,
|
||||
EMA or EcoAccount.
|
||||
|
||||
"""
|
||||
responsible = models.OneToOneField(
|
||||
@@ -112,9 +112,6 @@ class AbstractCompensation(BaseObject):
|
||||
geometry = models.ForeignKey(Geometry, null=True, blank=True, on_delete=models.SET_NULL)
|
||||
documents = models.ManyToManyField("konova.Document", blank=True)
|
||||
|
||||
# Holds a successor for this data
|
||||
next_version = models.ForeignKey("Compensation", null=True, blank=True, on_delete=models.DO_NOTHING)
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
|
||||
@@ -7,5 +7,6 @@ Created on: 18.12.20
|
||||
"""
|
||||
COMPENSATION_IDENTIFIER_LENGTH = 10
|
||||
COMPENSATION_IDENTIFIER_TEMPLATE = "KOM-{}"
|
||||
|
||||
ECO_ACCOUNT_IDENTIFIER_LENGTH = 10
|
||||
ECO_ACCOUNT_IDENTIFIER_TEMPLATE = "OEK-{}"
|
||||
@@ -5,7 +5,6 @@ Contact: michel.peltriaux@sgdnord.rlp.de
|
||||
Created on: 01.12.20
|
||||
|
||||
"""
|
||||
from django.db.models import Sum
|
||||
from django.http import HttpRequest
|
||||
from django.template.loader import render_to_string
|
||||
from django.urls import reverse
|
||||
@@ -15,7 +14,6 @@ from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from compensation.filters import CompensationTableFilter, EcoAccountTableFilter
|
||||
from compensation.models import Compensation, EcoAccount
|
||||
from intervention.filters import InterventionTableFilter
|
||||
from konova.sub_settings.django_settings import DEFAULT_DATE_TIME_FORMAT
|
||||
from konova.utils.tables import BaseTable
|
||||
import django_tables2 as tables
|
||||
@@ -53,7 +51,7 @@ class CompensationTable(BaseTable):
|
||||
lm = tables.Column(
|
||||
verbose_name=_("Last edit"),
|
||||
orderable=True,
|
||||
accessor="created__timestamp",
|
||||
accessor="modified__timestamp",
|
||||
)
|
||||
|
||||
class Meta(BaseTable.Meta):
|
||||
@@ -126,21 +124,21 @@ class CompensationTable(BaseTable):
|
||||
|
||||
"""
|
||||
html = ""
|
||||
checked = value is not None
|
||||
recorded = value is not None
|
||||
tooltip = _("Not recorded yet")
|
||||
if checked:
|
||||
if recorded:
|
||||
value = value.timestamp
|
||||
value = localtime(value)
|
||||
on = value.strftime(DEFAULT_DATE_TIME_FORMAT)
|
||||
tooltip = _("Recorded on {} by {}").format(on, record.intervention.recorded.user)
|
||||
html += self.render_bookmark(
|
||||
tooltip=tooltip,
|
||||
icn_filled=checked,
|
||||
icn_filled=recorded,
|
||||
)
|
||||
return format_html(html)
|
||||
|
||||
def render_e(self, value, record: Compensation):
|
||||
""" Renders the registered column for a compensation
|
||||
""" Renders the editable column for a compensation
|
||||
|
||||
Args:
|
||||
value (str): The identifier value
|
||||
@@ -192,7 +190,7 @@ class EcoAccountTable(BaseTable):
|
||||
lm = tables.Column(
|
||||
verbose_name=_("Last edit"),
|
||||
orderable=True,
|
||||
accessor="created__timestamp",
|
||||
accessor="modified__timestamp",
|
||||
)
|
||||
|
||||
class Meta(BaseTable.Meta):
|
||||
|
||||
@@ -118,7 +118,7 @@ def log_view(request: HttpRequest, id: str):
|
||||
|
||||
context = {
|
||||
"modal_body_template": body_template,
|
||||
"log": comp.log.all().order_by("-timestamp"),
|
||||
"log": comp.log.all(),
|
||||
"modal_title": _("Log"),
|
||||
}
|
||||
context = BaseContext(request, context).context
|
||||
|
||||
@@ -180,7 +180,7 @@ def log_view(request: HttpRequest, id: str):
|
||||
|
||||
context = {
|
||||
"modal_body_template": body_template,
|
||||
"log": comp.log.all().order_by("-timestamp"),
|
||||
"log": comp.log.all(),
|
||||
"modal_title": _("Log"),
|
||||
}
|
||||
context = BaseContext(request, context).context
|
||||
|
||||
@@ -6,18 +6,15 @@ Created on: 09.08.21
|
||||
|
||||
"""
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.http import HttpRequest
|
||||
from django.shortcuts import get_object_or_404, render, redirect
|
||||
from django.shortcuts import get_object_or_404
|
||||
|
||||
from compensation.forms import NewPaymentForm
|
||||
from compensation.models import Payment
|
||||
from intervention.models import Intervention
|
||||
from konova.contexts import BaseContext
|
||||
from konova.decorators import default_group_required
|
||||
from konova.forms import RemoveModalForm
|
||||
from konova.utils.message_templates import FORM_INVALID
|
||||
|
||||
|
||||
@login_required
|
||||
@@ -34,29 +31,10 @@ def new_payment_view(request: HttpRequest, intervention_id: str):
|
||||
"""
|
||||
intervention = get_object_or_404(Intervention, id=intervention_id)
|
||||
form = NewPaymentForm(request.POST or None, instance=intervention, user=request.user)
|
||||
template = form.template
|
||||
if request.method == "POST":
|
||||
if form.is_valid():
|
||||
payment = form.save()
|
||||
messages.success(
|
||||
request,
|
||||
_("Payment added")
|
||||
)
|
||||
return redirect(request.META.get("HTTP_REFERER", "home"))
|
||||
else:
|
||||
messages.info(
|
||||
request,
|
||||
FORM_INVALID
|
||||
)
|
||||
return redirect(request.META.get("HTTP_REFERER", "home"))
|
||||
elif request.method == "GET":
|
||||
context = {
|
||||
"form": form,
|
||||
}
|
||||
context = BaseContext(request, context).context
|
||||
return render(request, template, context)
|
||||
else:
|
||||
raise NotImplementedError
|
||||
return form.process_request(
|
||||
request,
|
||||
msg_success=_("Payment added")
|
||||
)
|
||||
|
||||
|
||||
@login_required
|
||||
|
||||
Reference in New Issue
Block a user