51 lines
1.4 KiB
Python
51 lines
1.4 KiB
Python
"""
|
|
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, render
|
|
from django.utils.translation import gettext_lazy as _
|
|
|
|
from konova.contexts import BaseContext
|
|
from konova.views.base import BaseView
|
|
|
|
|
|
class AbstractLogView(BaseView):
|
|
_MODEL_CLS = None
|
|
_TEMPLATE = "modal/modal_generic.html"
|
|
|
|
class Meta:
|
|
abstract = True
|
|
|
|
def get(self, request, id: str):
|
|
""" Renders a log view using modal
|
|
|
|
Args:
|
|
request (HttpRequest): The incoming request
|
|
id (str): The object's id
|
|
|
|
Returns:
|
|
|
|
"""
|
|
intervention = get_object_or_404(self._MODEL_CLS, id=id)
|
|
body_template = "log.html"
|
|
|
|
context = {
|
|
"modal_body_template": body_template,
|
|
"log": intervention.log.iterator(),
|
|
"modal_title": _("Log"),
|
|
}
|
|
context = BaseContext(request, context).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()
|