EMA
* 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
This commit is contained in:
+221
-6
@@ -1,16 +1,24 @@
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.db.models import Sum
|
||||
from django.http import HttpRequest
|
||||
from django.shortcuts import render, get_object_or_404
|
||||
from django.urls import reverse
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
import compensation
|
||||
from compensation.forms import NewStateModalForm, NewActionModalForm, NewDeadlineModalForm
|
||||
from ema.tables import EmaTable
|
||||
from konova.contexts import BaseContext
|
||||
from konova.decorators import conservation_office_group_required
|
||||
from ema.models import Ema
|
||||
from konova.forms import RemoveModalForm, NewDocumentForm, SimpleGeomForm, RecordForm
|
||||
from konova.settings import DEFAULT_GROUP, ZB_GROUP, ETS_GROUP
|
||||
from konova.utils.user_checks import in_group
|
||||
|
||||
|
||||
@login_required
|
||||
def index_view(request: HttpRequest):
|
||||
""" Renders the index view for MAEs
|
||||
""" Renders the index view for EMAs
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
@@ -38,7 +46,7 @@ def index_view(request: HttpRequest):
|
||||
@login_required
|
||||
@conservation_office_group_required
|
||||
def new_view(request: HttpRequest):
|
||||
""" Renders the form for a new MAE
|
||||
""" Renders the form for a new EMA
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
@@ -54,17 +62,224 @@ def new_view(request: HttpRequest):
|
||||
|
||||
@login_required
|
||||
def open_view(request: HttpRequest, id: str):
|
||||
""" Renders the form for a new MAE
|
||||
""" Renders the detail view of an EMA
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
id (str): The MAE id
|
||||
id (str): The EMA id
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
template = "ema/detail/view.html"
|
||||
ema = get_object_or_404(Ema, id=id, deleted=None)
|
||||
|
||||
geom_form = SimpleGeomForm(instance=ema)
|
||||
_user = request.user
|
||||
is_data_shared = ema.is_shared_with(_user)
|
||||
|
||||
# Order states according to surface
|
||||
before_states = ema.before_states.all().order_by("-surface")
|
||||
after_states = ema.after_states.all().order_by("-surface")
|
||||
|
||||
# Precalculate logical errors between before- and after-states
|
||||
# Sum() returns None in case of no states, so we catch that and replace it with 0 for easier handling
|
||||
sum_before_states = before_states.aggregate(Sum("surface"))["surface__sum"] or 0
|
||||
sum_after_states = after_states.aggregate(Sum("surface"))["surface__sum"] or 0
|
||||
diff_states = abs(sum_before_states - sum_after_states)
|
||||
|
||||
context = {
|
||||
"obj": ema,
|
||||
"geom_form": geom_form,
|
||||
"has_access": is_data_shared,
|
||||
"before_states": before_states,
|
||||
"after_states": after_states,
|
||||
"sum_before_states": sum_before_states,
|
||||
"sum_after_states": sum_after_states,
|
||||
"diff_states": diff_states,
|
||||
"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": ema.get_LANIS_link(),
|
||||
}
|
||||
context = BaseContext(request, context).context
|
||||
return render(request, template, context)
|
||||
|
||||
|
||||
@login_required
|
||||
def log_view(request: HttpRequest, id: str):
|
||||
""" Renders a log view using modal
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
id (str): The EMA's id
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
ema = get_object_or_404(Ema, id=id)
|
||||
template = "generic_index.html"
|
||||
context = {}
|
||||
template = "modal/modal_generic.html"
|
||||
body_template = "log.html"
|
||||
|
||||
context = {
|
||||
"modal_body_template": body_template,
|
||||
"log": ema.log.all(),
|
||||
"modal_title": _("Log"),
|
||||
}
|
||||
context = BaseContext(request, context).context
|
||||
return render(request, template, context)
|
||||
|
||||
|
||||
@login_required
|
||||
def edit_view(request: HttpRequest, id: str):
|
||||
get_object_or_404(Ema, id=id)
|
||||
|
||||
|
||||
@login_required
|
||||
def remove_view(request: HttpRequest, id: str):
|
||||
""" Renders a modal view for removing the EMA
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
id (str): The EMA's id
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
ema = get_object_or_404(Ema, id=id)
|
||||
form = RemoveModalForm(request.POST or None, instance=ema, user=request.user)
|
||||
return form.process_request(
|
||||
request=request,
|
||||
msg_success=_("EMA removed"),
|
||||
redirect_url=reverse("ema:index"),
|
||||
)
|
||||
|
||||
|
||||
@login_required
|
||||
def record_view(request: HttpRequest, id: str):
|
||||
""" Renders a modal view for recording the EMA
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
id (str): The EMA's id
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
ema = get_object_or_404(Ema, id=id)
|
||||
form = RecordForm(request.POST or None, instance=ema, user=request.user)
|
||||
return form.process_request(
|
||||
request=request,
|
||||
msg_success=_("EMA recorded"),
|
||||
)
|
||||
|
||||
|
||||
@login_required
|
||||
def state_new_view(request: HttpRequest, id: str):
|
||||
""" Renders a form for adding new states for an EMA
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
id (str): The EMA's id to which the new state will be related
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
ema = get_object_or_404(Ema, id=id)
|
||||
form = NewStateModalForm(request.POST or None, instance=ema, user=request.user)
|
||||
return form.process_request(
|
||||
request,
|
||||
msg_success=_("State added")
|
||||
)
|
||||
|
||||
|
||||
@login_required
|
||||
def action_new_view(request: HttpRequest, id: str):
|
||||
""" Renders a form for adding new actions for an EMA
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
id (str): The EMA's id to which the new state will be related
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
ema = get_object_or_404(Ema, id=id)
|
||||
form = NewActionModalForm(request.POST or None, instance=ema, user=request.user)
|
||||
return form.process_request(
|
||||
request,
|
||||
msg_success=_("Action added")
|
||||
)
|
||||
|
||||
|
||||
@login_required
|
||||
def deadline_new_view(request: HttpRequest, id: str):
|
||||
""" Renders a form for adding new states for an EMA
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
id (str): The EMA's id to which the new state will be related
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
ema = get_object_or_404(Ema, id=id)
|
||||
form = NewDeadlineModalForm(request.POST or None, instance=ema, user=request.user)
|
||||
return form.process_request(
|
||||
request,
|
||||
msg_success=_("Deadline added")
|
||||
)
|
||||
|
||||
|
||||
@login_required
|
||||
def document_new_view(request: HttpRequest, id: str):
|
||||
""" Renders a form for uploading new documents
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
id (str): The EMA's id to which the new document will be related
|
||||
Returns:
|
||||
|
||||
"""
|
||||
ema = get_object_or_404(Ema, id=id)
|
||||
form = NewDocumentForm(request.POST or None, request.FILES or None, instance=ema, user=request.user)
|
||||
return form.process_request(
|
||||
request,
|
||||
msg_success=_("Document added")
|
||||
)
|
||||
|
||||
|
||||
@login_required
|
||||
def state_remove_view(request: HttpRequest, id: str):
|
||||
""" Renders a form for removing an EMA state
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
id (str): The state's id
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
return compensation.views.compensation_views.state_remove_view(
|
||||
request,
|
||||
id
|
||||
)
|
||||
|
||||
|
||||
@login_required
|
||||
def action_remove_view(request: HttpRequest, id: str):
|
||||
""" Renders a form for removing an EMA state
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
id (str): The state's id
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
# Reuses the route logic from compensation view
|
||||
return compensation.views.compensation_views.action_remove_view(
|
||||
request,
|
||||
id
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user