Intervention revocation

* adds Revocation model to interventions/models.py
* adds revocations to interventions detail view
* fixes duplicated ids in html includes
* refactors controls for detail view into included template files (controls.html)
* reduces max length for payment transfer notes from 1000 to 200
* adds RevocationAdmin to intervention/admin.py
* adds new form for adding a Revocation to an intervention's legal_data
  * only one revocation per intervention possible
  * removes add button in case of an existing revocation
* adds revocation routes to intervention app
* renames document field in Document model into file for more clarity
* adds/updates translations
This commit is contained in:
mipel
2021-08-04 13:32:35 +02:00
parent fd526b80b7
commit 8e1f679c2a
25 changed files with 495 additions and 197 deletions

View File

@@ -4,12 +4,14 @@ from django.utils.translation import gettext_lazy as _
from django.http import HttpRequest
from django.shortcuts import render, get_object_or_404
from intervention.forms import NewInterventionForm, EditInterventionForm, ShareInterventionForm
from intervention.models import Intervention
from intervention.forms import NewInterventionForm, EditInterventionForm, ShareInterventionForm, NewRevocationForm
from intervention.models import Intervention, Revocation
from intervention.tables import InterventionTable
from konova.contexts import BaseContext
from konova.decorators import *
from konova.forms import SimpleGeomForm, NewDocumentForm, RemoveModalForm
from konova.sub_settings.django_settings import DEFAULT_DATE_TIME_FORMAT, DEFAULT_DATE_FORMAT
from konova.utils.message_templates import FORM_INVALID
from konova.utils.user_checks import in_group
@@ -117,6 +119,14 @@ def open_view(request: HttpRequest, id: str):
instance=intervention
)
# Inform user about revocation
if intervention.legal.revocation:
messages.error(
request,
_("This intervention has a revocation from {}").format(intervention.legal.revocation.date.strftime(DEFAULT_DATE_FORMAT)),
extra_tags="danger",
)
context = {
"intervention": intervention,
"compensations": compensations,
@@ -185,6 +195,26 @@ def remove_view(request: HttpRequest, id: str):
)
@login_required
@default_group_required
def remove_revocation_view(request: HttpRequest, id: str):
""" Renders a remove view for a revocation
Args:
request (HttpRequest): The incoming request
id (str): The revocation's id as string
Returns:
"""
obj = Revocation.objects.get(id=id)
form = RemoveModalForm(request.POST or None, instance=obj, user=request.user)
return form.process_request(
request,
_("Revocation removed"),
)
@login_required
def share_view(request: HttpRequest, id: str, token: str):
""" Performs sharing of an intervention
@@ -256,3 +286,40 @@ def create_share_view(request: HttpRequest, id: str):
raise NotImplementedError
@login_required
def new_revocation_view(request: HttpRequest, id: str):
""" Renders sharing form for an intervention
Args:
request (HttpRequest): The incoming request
id (str): Intervention's id
Returns:
"""
intervention = get_object_or_404(Intervention, id=id)
form = NewRevocationForm(request.POST or None, request.FILES or None, instance=intervention, user=request.user)
if request.method == "POST":
if form.is_valid():
form.save()
messages.info(
request,
_("Revocation added")
)
else:
messages.error(
request,
FORM_INVALID,
extra_tags="danger",
)
return redirect(request.META.get("HTTP_REFERER", "home"))
elif request.method == "GET":
context = {
"form": form,
}
context = BaseContext(request, context).context
return render(request, form.template, context)
else:
raise NotImplementedError