WIP: 490_View_refactoring #491

Draft
mpeltriaux wants to merge 36 commits from 490_View_refactoring into master
5 changed files with 30 additions and 53 deletions
Showing only changes of commit 1fc1b533cd - Show all commits

View File

@ -5,20 +5,11 @@ Contact: ksp-servicestelle@sgdnord.rlp.de
Created on: 19.08.22 Created on: 19.08.22
""" """
from django.contrib.auth.decorators import login_required from django.contrib.auth.mixins import LoginRequiredMixin
from django.utils.decorators import method_decorator
from compensation.models import Compensation from compensation.models import Compensation
from konova.decorators import shared_access_required, default_group_required, login_required_modal
from konova.views.log import AbstractLogView from konova.views.log import AbstractLogView
class CompensationLogView(AbstractLogView): class CompensationLogView(LoginRequiredMixin, AbstractLogView):
model = Compensation _MODEL_CLS = Compensation
@method_decorator(login_required_modal)
@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

@ -5,20 +5,11 @@ Contact: ksp-servicestelle@sgdnord.rlp.de
Created on: 19.08.22 Created on: 19.08.22
""" """
from django.contrib.auth.decorators import login_required from django.contrib.auth.mixins import LoginRequiredMixin
from django.utils.decorators import method_decorator
from compensation.models import EcoAccount from compensation.models import EcoAccount
from konova.decorators import shared_access_required, default_group_required, login_required_modal
from konova.views.log import AbstractLogView from konova.views.log import AbstractLogView
class EcoAccountLogView(AbstractLogView): class EcoAccountLogView(LoginRequiredMixin, AbstractLogView):
model = EcoAccount _MODEL_CLS = EcoAccount
@method_decorator(login_required_modal)
@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)

View File

@ -5,20 +5,14 @@ Contact: ksp-servicestelle@sgdnord.rlp.de
Created on: 19.08.22 Created on: 19.08.22
""" """
from django.contrib.auth.decorators import login_required from django.contrib.auth.mixins import LoginRequiredMixin
from django.utils.decorators import method_decorator
from ema.models import Ema from ema.models import Ema
from konova.decorators import shared_access_required, conservation_office_group_required, login_required_modal
from konova.views.log import AbstractLogView from konova.views.log import AbstractLogView
class EmaLogView(AbstractLogView): class EmaLogView(LoginRequiredMixin, AbstractLogView):
model = Ema _MODEL_CLS = Ema
@method_decorator(login_required_modal) def _user_has_permission(self, user):
@method_decorator(login_required) return user.is_ets_user()
@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)

View File

@ -5,19 +5,11 @@ Contact: ksp-servicestelle@sgdnord.rlp.de
Created on: 19.08.22 Created on: 19.08.22
""" """
from django.contrib.auth.decorators import login_required from django.contrib.auth.mixins import LoginRequiredMixin
from django.utils.decorators import method_decorator
from intervention.models import Intervention from intervention.models import Intervention
from konova.decorators import shared_access_required, default_group_required
from konova.views.log import AbstractLogView from konova.views.log import AbstractLogView
class InterventionLogView(AbstractLogView): class InterventionLogView(LoginRequiredMixin, AbstractLogView):
model = Intervention _MODEL_CLS = Intervention
@method_decorator(login_required)
@method_decorator(default_group_required)
@method_decorator(shared_access_required(Intervention, "id"))
def dispatch(self, request, *args, **kwargs):
return super().dispatch(request, *args, **kwargs)

View File

@ -6,14 +6,15 @@ Created on: 19.08.22
""" """
from django.shortcuts import get_object_or_404, render from django.shortcuts import get_object_or_404, render
from django.views import View
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from konova.contexts import BaseContext from konova.contexts import BaseContext
from konova.views.base import BaseView
class AbstractLogView(View): class AbstractLogView(BaseView):
model = None _MODEL_CLS = None
_TEMPLATE = "modal/modal_generic.html"
class Meta: class Meta:
abstract = True abstract = True
@ -28,14 +29,22 @@ class AbstractLogView(View):
Returns: Returns:
""" """
intervention = get_object_or_404(self.model, id=id) intervention = get_object_or_404(self._MODEL_CLS, id=id)
template = "modal/modal_generic.html"
body_template = "log.html" body_template = "log.html"
context = { context = {
"modal_body_template": body_template, "modal_body_template": body_template,
"log": intervention.log.all(), "log": intervention.log.iterator(),
"modal_title": _("Log"), "modal_title": _("Log"),
} }
context = BaseContext(request, context).context context = BaseContext(request, context).context
return render(request, template, context) return render(request, self._TEMPLATE, context)
def _user_has_shared_access(self, user, **kwargs):
obj_id = kwargs.get('id', None)
assert obj_id is not None
obj = get_object_or_404(self._MODEL_CLS, id=obj_id)
return obj.is_shared_with(user)
def _user_has_permission(self, user):
return user.is_default_user()