Remove add permission if week expired
This commit is contained in:
@@ -51,7 +51,6 @@ class HourBuildingLegBaseInLine(nested_admin.NestedStackedPolymorphicInline):
|
||||
form = HourBuildingLegFlightForm
|
||||
fk_name = "hourbuildinglegbase_ptr"
|
||||
fields = ("departure", "time", "destination", "pax", )
|
||||
hide_title = True
|
||||
|
||||
class HourBuildingLegStopInLine(nested_admin.NestedStackedPolymorphicInline.Child):
|
||||
model = HourBuildingLegStop
|
||||
@@ -65,7 +64,7 @@ class HourBuildingLegBaseInLine(nested_admin.NestedStackedPolymorphicInline):
|
||||
def has_change_permission(self, request: HttpRequest, obj: HourBuilding | None = None):
|
||||
if hasattr(request.user, "student") and obj:
|
||||
current_week = date.today().isocalendar().week
|
||||
if not obj.DoesNotExist and current_week > obj.weekpref.week:
|
||||
if current_week > obj.weekpref.week:
|
||||
return False
|
||||
return True
|
||||
|
||||
@@ -85,3 +84,16 @@ class HourBuildingInLine(nested_admin.NestedTabularInline):
|
||||
models.TextField: {"widget": Textarea(attrs={"rows":4, "cols":35})},
|
||||
}
|
||||
|
||||
# If user is a student deny edit permission for week past the current one
|
||||
def has_change_permission(self, request: HttpRequest, obj: WeekPreference | None = None):
|
||||
if hasattr(request.user, 'student') and obj:
|
||||
current_week: int = date.today().isocalendar().week
|
||||
if current_week > obj.week:
|
||||
return False
|
||||
return True
|
||||
|
||||
def has_delete_permission(self, request: HttpRequest, obj: WeekPreference | None = None):
|
||||
return self.has_change_permission(request=request, obj=obj)
|
||||
|
||||
def has_add_permission(self, request: HttpRequest, obj: WeekPreference | None = None):
|
||||
return self.has_change_permission(request=request, obj=obj)
|
||||
|
||||
Reference in New Issue
Block a user