Refactoring to konova

This commit is contained in:
mipel
2021-07-01 14:38:57 +02:00
parent c14e9466fb
commit 947f50b11c
60 changed files with 103 additions and 17901 deletions

44
konova/decorators.py Normal file
View File

@@ -0,0 +1,44 @@
"""
Author: Michel Peltriaux
Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany
Contact: michel.peltriaux@sgdnord.rlp.de
Created on: 16.11.20
"""
from functools import wraps
from django.contrib import messages
from django.shortcuts import redirect
from django.urls import reverse
from django.utils.translation import gettext_lazy as _
def staff_required(function):
"""
A decorator for functions which shall only be usable for staff members of the system
"""
@wraps(function)
def wrap(request, *args, **kwargs):
user = request.user
if user.is_staff:
return function(request, *args, **kwargs)
else:
messages.info(request, _("You need to be staff to perform this action!"))
return redirect(request.META.get("HTTP_REFERER", reverse("home")))
return wrap
def superuser_required(function):
"""
A decorator for functions which shall only be usable for superusers of the system
"""
@wraps(function)
def wrap(request, *args, **kwargs):
user = request.user
if user.is_superuser:
return function(request, *args, **kwargs)
else:
messages.info(request, _("You need to be administrator to perform this action!"))
return redirect(request.META.get("HTTP_REFERER", reverse("home")))
return wrap