Record class view
* adds AbstractRecordView to konova/views/record.py * implements for all major data types
This commit is contained in:
parent
ef3507f058
commit
7b35591f5d
@ -11,7 +11,7 @@ from compensation.autocomplete.eco_account import EcoAccountAutocomplete
|
||||
from compensation.views.eco_account.eco_account import index_view, new_view, new_id_view, edit_view, remove_view, \
|
||||
detail_view
|
||||
from compensation.views.eco_account.log import EcoAccountLogView
|
||||
from compensation.views.eco_account.record import record_view
|
||||
from compensation.views.eco_account.record import EcoAccountRecordView
|
||||
from compensation.views.eco_account.report import report_view
|
||||
from compensation.views.eco_account.resubmission import EcoAccountResubmissionView
|
||||
from compensation.views.eco_account.state import state_new_view, state_remove_view, state_edit_view
|
||||
@ -29,7 +29,7 @@ urlpatterns = [
|
||||
path('new/id', new_id_view, name='new-id'),
|
||||
path('<id>', detail_view, name='detail'),
|
||||
path('<id>/log', EcoAccountLogView.as_view(), name='log'),
|
||||
path('<id>/record', record_view, name='record'),
|
||||
path('<id>/record', EcoAccountRecordView.as_view(), name='record'),
|
||||
path('<id>/report', report_view, name='report'),
|
||||
path('<id>/edit', edit_view, name='edit'),
|
||||
path('<id>/remove', remove_view, name='remove'),
|
||||
|
@ -6,33 +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 compensation.models import EcoAccount
|
||||
from konova.decorators import shared_access_required, conservation_office_group_required
|
||||
from konova.forms.modals import RecordModalForm
|
||||
from konova.views.record import AbstractRecordView
|
||||
|
||||
|
||||
@login_required
|
||||
@conservation_office_group_required
|
||||
@shared_access_required(EcoAccount, "id")
|
||||
def record_view(request: HttpRequest, id:str):
|
||||
""" Renders a modal form for recording an eco account
|
||||
class EcoAccountRecordView(AbstractRecordView):
|
||||
model = EcoAccount
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
id (str): The account's id
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
acc = get_object_or_404(EcoAccount, id=id)
|
||||
form = RecordModalForm(request.POST or None, instance=acc, request=request)
|
||||
msg_succ = _("{} unrecorded") if acc.recorded else _("{} recorded")
|
||||
msg_succ = msg_succ.format(acc.identifier)
|
||||
return form.process_request(
|
||||
request,
|
||||
msg_succ
|
||||
)
|
||||
@method_decorator(login_required)
|
||||
@method_decorator(conservation_office_group_required)
|
||||
@method_decorator(shared_access_required(EcoAccount, "id"))
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
@ -12,7 +12,7 @@ from ema.views.deadline import deadline_new_view, deadline_edit_view, deadline_r
|
||||
from ema.views.document import document_new_view, get_document_view, remove_document_view, edit_document_view
|
||||
from ema.views.ema import index_view, new_view, new_id_view, detail_view, edit_view, remove_view
|
||||
from ema.views.log import EmaLogView
|
||||
from ema.views.record import record_view
|
||||
from ema.views.record import EmaRecordView
|
||||
from ema.views.report import report_view
|
||||
from ema.views.resubmission import EmaResubmissionView
|
||||
from ema.views.share import share_view, create_share_view
|
||||
@ -27,7 +27,7 @@ urlpatterns = [
|
||||
path('<id>/log', EmaLogView.as_view(), name='log'),
|
||||
path('<id>/edit', edit_view, name='edit'),
|
||||
path('<id>/remove', remove_view, name='remove'),
|
||||
path('<id>/record', record_view, name='record'),
|
||||
path('<id>/record', EmaRecordView.as_view(), name='record'),
|
||||
path('<id>/report', report_view, name='report'),
|
||||
path('<id>/resub', EmaResubmissionView.as_view(), name='resubmission-create'),
|
||||
|
||||
|
@ -6,32 +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 ema.models import Ema
|
||||
from konova.decorators import shared_access_required, conservation_office_group_required
|
||||
from konova.forms.modals import RecordModalForm
|
||||
from konova.views.record import AbstractRecordView
|
||||
|
||||
|
||||
@login_required
|
||||
@conservation_office_group_required
|
||||
@shared_access_required(Ema, "id")
|
||||
def record_view(request: HttpRequest, id: str):
|
||||
""" Renders a modal view for recording the EMA
|
||||
class EmaRecordView(AbstractRecordView):
|
||||
model = Ema
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
id (str): The EMA's id
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
ema = get_object_or_404(Ema, id=id)
|
||||
msg_succ = _("{} unrecorded") if ema.recorded else _("{} recorded")
|
||||
form = RecordModalForm(request.POST or None, instance=ema, request=request)
|
||||
return form.process_request(
|
||||
request=request,
|
||||
msg_success=msg_succ.format("EMA"),
|
||||
)
|
||||
@method_decorator(login_required)
|
||||
@method_decorator(conservation_office_group_required)
|
||||
@method_decorator(shared_access_required(Ema, "id"))
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
@ -14,7 +14,7 @@ from intervention.views.deduction import new_deduction_view, edit_deduction_view
|
||||
from intervention.views.document import new_document_view, get_document_view, remove_document_view, edit_document_view
|
||||
from intervention.views.intervention import index_view, new_view, new_id_view, detail_view, edit_view, remove_view
|
||||
from intervention.views.log import InterventionLogView
|
||||
from intervention.views.record import record_view
|
||||
from intervention.views.record import InterventionRecordView
|
||||
from intervention.views.report import report_view
|
||||
from intervention.views.resubmission import InterventionResubmissionView
|
||||
from intervention.views.revocation import new_revocation_view, edit_revocation_view, remove_revocation_view, \
|
||||
@ -33,7 +33,7 @@ urlpatterns = [
|
||||
path('<id>/share/<token>', share_view, name='share'),
|
||||
path('<id>/share', create_share_view, name='share-create'),
|
||||
path('<id>/check', check_view, name='check'),
|
||||
path('<id>/record', record_view, name='record'),
|
||||
path('<id>/record', InterventionRecordView.as_view(), name='record'),
|
||||
path('<id>/report', report_view, name='report'),
|
||||
path('<id>/resub', InterventionResubmissionView.as_view(), name='resubmission-create'),
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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
50
konova/views/record.py
Normal 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)
|
@ -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:
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user