centralized student permission in one function

This commit is contained in:
2025-12-01 14:39:09 +01:00
parent a31798d0b0
commit f06f269568
4 changed files with 26 additions and 21 deletions

View File

@@ -0,0 +1,17 @@
from django.http import HttpRequest
from ..models.students import Student
from ..models.weekpref import WeekPreference
from datetime import date
# allow add, modify, delete depending on a set of requirements
def has_edit_permission(request: HttpRequest, obj: WeekPreference | None = None) -> bool:
if hasattr(request.user, 'student'):
student: Student = request.user.student
if not student.active:
return False
current_week: int = date.today().isocalendar().week
if obj and current_week > obj.week or not student.active:
return False
return True