takahe/users/decorators.py

16 lines
470 B
Python
Raw Normal View History

2022-11-05 20:17:27 +00:00
from functools import wraps
from django.contrib.auth.decorators import user_passes_test
2022-11-05 20:17:27 +00:00
from django.contrib.auth.views import redirect_to_login
from django.http import HttpResponseRedirect
2022-12-20 09:01:54 +00:00
def moderator_required(function):
return user_passes_test(
lambda user: user.is_authenticated and (user.admin or user.moderator)
)(function)
def admin_required(function):
return user_passes_test(lambda user: user.is_authenticated and user.admin)(function)