centralized student permission in one function
This commit is contained in:
17
cntmanage/flightslot/custom/student_permissions.py
Normal file
17
cntmanage/flightslot/custom/student_permissions.py
Normal 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
|
||||
Reference in New Issue
Block a user