Record class view

* adds AbstractRecordView to konova/views/record.py
    * implements for all major data types
This commit is contained in:
2022-08-19 11:01:33 +02:00
parent ef3507f058
commit 7b35591f5d
9 changed files with 86 additions and 81 deletions

View File

@@ -6,34 +6,18 @@ Created on: 19.08.22
"""
from django.contrib.auth.decorators import login_required
from django.http import HttpRequest
from django.shortcuts import get_object_or_404
from django.utils.translation import gettext_lazy as _
from django.utils.decorators import method_decorator
from intervention.models import Intervention
from konova.decorators import conservation_office_group_required, shared_access_required
from konova.forms.modals import RecordModalForm
from konova.views.record import AbstractRecordView
@login_required
@conservation_office_group_required
@shared_access_required(Intervention, "id")
def record_view(request: HttpRequest, id: str):
""" Renders a modal form for recording an intervention
class InterventionRecordView(AbstractRecordView):
model = Intervention
Args:
request (HttpRequest): The incoming request
id (str): The intervention's id
Returns:
"""
intervention = get_object_or_404(Intervention, id=id)
form = RecordModalForm(request.POST or None, instance=intervention, request=request)
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:")
)
@method_decorator(login_required)
@method_decorator(conservation_office_group_required)
@method_decorator(shared_access_required(Intervention, "id"))
def dispatch(self, request, *args, **kwargs):
return super().dispatch(request, *args, **kwargs)