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 096385a9eb
commit c80145366e
9 changed files with 86 additions and 81 deletions

View File

@@ -23,7 +23,7 @@ class AbstractLogView(View):
Args:
request (HttpRequest): The incoming request
id (str): The compensation's id
id (str): The object's id
Returns:

50
konova/views/record.py Normal file
View File

@@ -0,0 +1,50 @@
"""
Author: Michel Peltriaux
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
Contact: ksp-servicestelle@sgdnord.rlp.de
Created on: 19.08.22
"""
from django.shortcuts import get_object_or_404
from django.views import View
from django.utils.translation import gettext_lazy as _
from konova.forms.modals import RecordModalForm
class AbstractRecordView(View):
model = None
def get(self, request, id: str):
""" Renders a modal form for recording an object
Args:
request (HttpRequest): The incoming request
id (str): The object's id
Returns:
"""
obj = get_object_or_404(self.model, id=id)
form = RecordModalForm(request.POST or None, instance=obj, request=request)
msg_succ = _("{} unrecorded") if obj.recorded else _("{} recorded")
msg_succ = msg_succ.format(obj.identifier)
return form.process_request(
request,
msg_succ,
msg_error=_("Errors found:")
)
def post(self, request, id: str):
"""
BaseModalForm provides the method process_request() which handles GET as well as POST requests. It was written
for easier handling of function based views. To support process_request() on class based views, the post()
call needs to be treated the same way as the get() call.
Args:
request (HttpRequest): The incoming request
id (str): Intervention's id
"""
return self.get(request, id)

View File

@@ -22,11 +22,11 @@ class AbstractResubmissionView(View):
abstract = True
def get(self, request, id: str):
""" Renders resubmission form for an intervention
""" Renders resubmission form for an object
Args:
request (HttpRequest): The incoming request
id (str): Intervention's id
id (str): Object's id
Returns: