Recording data

* adds dynamic icon for recording and unrecording of data
* adds record view to intervention and eco accounts
* adds quality_check() method for Intervention and EcoAccount class which holds logic for data quality checking
* adds UserAction "unrecorded"
This commit is contained in:
mipel
2021-08-10 17:19:42 +02:00
parent bd2413d63c
commit 5f85f49636
15 changed files with 291 additions and 122 deletions

View File

@@ -10,9 +10,9 @@ 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.forms import SimpleGeomForm, NewDocumentForm, RemoveModalForm, RecordForm
from konova.sub_settings.django_settings import DEFAULT_DATE_FORMAT
from konova.utils.message_templates import FORM_INVALID
from konova.utils.message_templates import FORM_INVALID, INTERVENTION_INVALID
from konova.utils.user_checks import in_group
@@ -304,34 +304,11 @@ def run_check_view(request: HttpRequest, id: str):
"""
intervention = get_object_or_404(Intervention, id=id)
form = RunCheckForm(request.POST or None, instance=intervention, user=request.user)
if request.method == "POST":
if form.is_valid():
form.save()
messages.info(
request,
_("Check performed")
)
else:
messages.error(
request,
_("There has been errors on this intervention:"),
extra_tags="danger"
)
for error_name, error_val in form.errors.items():
messages.error(
request,
_("{}: {}").format(_(error_name), _(error_val)),
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
return form.process_request(
request,
msg_success=_("Check performed"),
msg_error=INTERVENTION_INVALID
)
@login_required
@@ -413,3 +390,26 @@ def new_withdraw_view(request: HttpRequest, id: str):
request,
msg_success=_("Withdraw added")
)
@login_required
@conservation_office_group_required
def record_view(request: HttpRequest, id: str):
""" Renders a modal form for recording an intervention
Args:
request (HttpRequest): The incoming request
id (str): The intervention's id
Returns:
"""
intervention = get_object_or_404(Intervention, id=id)
form = RecordForm(request.POST or None, instance=intervention, user=request.user)
msg_succ = _("{} unrecorded") if intervention.recorded else _("{} recorded")
msg_succ = msg_succ.format(intervention.identifier)
return form.process_request(
request,
msg_succ,
msg_error=_("There are errors on this intervention:")
)