Konova views

* splits konova/views.py into separate files in new module
    * view files can now be found in /konova/views/...
* introduces first class based view AbstractLogView
    * implemented for Ema, Intervention, Compensation and EcoAccount
This commit is contained in:
2022-08-19 10:25:27 +02:00
parent 9654f6873d
commit 7e68d12ee9
17 changed files with 387 additions and 368 deletions

View File

@@ -16,7 +16,7 @@ from compensation.views.compensation.action import action_edit_view, action_new_
from compensation.views.compensation.state import state_new_view, state_remove_view, state_edit_view
from compensation.views.compensation.compensation import index_view, new_view, new_id_view, detail_view, edit_view, \
remove_view
from compensation.views.compensation.log import log_view
from compensation.views.compensation.log import CompensationLogView
urlpatterns = [
# Main compensation
@@ -25,7 +25,7 @@ urlpatterns = [
path('new/<intervention_id>', new_view, name='new'),
path('new', new_view, name='new'),
path('<id>', detail_view, name='detail'),
path('<id>/log', log_view, name='log'),
path('<id>/log', CompensationLogView.as_view(), name='log'),
path('<id>/edit', edit_view, name='edit'),
path('<id>/remove', remove_view, name='remove'),

View File

@@ -10,7 +10,7 @@ from django.urls import path
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 log_view
from compensation.views.eco_account.log import EcoAccountLogView
from compensation.views.eco_account.record import record_view
from compensation.views.eco_account.report import report_view
from compensation.views.eco_account.resubmission import create_resubmission_view
@@ -28,7 +28,7 @@ urlpatterns = [
path('new/', new_view, name='new'),
path('new/id', new_id_view, name='new-id'),
path('<id>', detail_view, name='detail'),
path('<id>/log', log_view, name='log'),
path('<id>/log', EcoAccountLogView.as_view(), name='log'),
path('<id>/record', record_view, name='record'),
path('<id>/report', report_view, name='report'),
path('<id>/edit', edit_view, name='edit'),

View File

@@ -6,36 +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, render
from django.utils.translation import gettext_lazy as _
from django.utils.decorators import method_decorator
from compensation.models import Compensation
from konova.contexts import BaseContext
from konova.decorators import shared_access_required, default_group_required
from konova.views.log import AbstractLogView
@login_required
@default_group_required
@shared_access_required(Compensation, "id")
def log_view(request: HttpRequest, id: str):
""" Renders a log view using modal
class CompensationLogView(AbstractLogView):
model = Compensation
Args:
request (HttpRequest): The incoming request
id (str): The compensation's id
Returns:
"""
comp = get_object_or_404(Compensation, id=id)
template = "modal/modal_generic.html"
body_template = "log.html"
context = {
"modal_body_template": body_template,
"log": comp.log.all(),
"modal_title": _("Log"),
}
context = BaseContext(request, context).context
return render(request, template, context)
@method_decorator(login_required)
@method_decorator(default_group_required)
@method_decorator(shared_access_required(Compensation, "id"))
def dispatch(self, request, *args, **kwargs):
return super().dispatch(request, *args, **kwargs)

View File

@@ -6,37 +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, render
from django.utils.translation import gettext_lazy as _
from django.utils.decorators import method_decorator
from compensation.models import EcoAccount
from konova.contexts import BaseContext
from konova.decorators import shared_access_required, default_group_required
from konova.views.log import AbstractLogView
@login_required
@default_group_required
@shared_access_required(EcoAccount, "id")
def log_view(request: HttpRequest, id: str):
""" Renders a log view using modal
Args:
request (HttpRequest): The incoming request
id (str): The eco acount's id
Returns:
"""
comp = get_object_or_404(EcoAccount, id=id)
template = "modal/modal_generic.html"
body_template = "log.html"
context = {
"modal_body_template": body_template,
"log": comp.log.all(),
"modal_title": _("Log"),
}
context = BaseContext(request, context).context
return render(request, template, context)
class EcoAccountLogView(AbstractLogView):
model = EcoAccount
@method_decorator(login_required)
@method_decorator(default_group_required)
@method_decorator(shared_access_required(EcoAccount, "id"))
def dispatch(self, request, *args, **kwargs):
return super().dispatch(request, *args, **kwargs)