Show Hour building only at ATPL or DL (volo) students
This commit is contained in:
@@ -7,6 +7,7 @@ from django.contrib import admin, messages
|
||||
from django.utils.translation import ngettext
|
||||
from django.utils.safestring import SafeText
|
||||
|
||||
from ..models.courses import CourseTypes
|
||||
from ..models.students import Student
|
||||
from ..models.missions import Training
|
||||
from ..models.weekpref import WeekPreference
|
||||
@@ -22,11 +23,10 @@ from datetime import date
|
||||
from typing import Dict, List, Any
|
||||
|
||||
class WeekPreferenceAdmin(nested_admin.NestedPolymorphicModelAdmin):
|
||||
inlines = (TrainingInLIne, HourBuildingInLine, )
|
||||
list_display = ("week", "student__surname","student__name", "student__course", "course_color", "student_brief_mix",)
|
||||
list_filter = ("week", "student__course",)
|
||||
search_fields = ("student__surname","student__name",)
|
||||
actions = ("export",)
|
||||
list_display = ("week", "student__surname", "student__name", "student__course", "course_color", "student_brief_mix", )
|
||||
list_filter = ("week", "student__course", )
|
||||
search_fields = ("student__surname","student__name", )
|
||||
actions = ("export", )
|
||||
|
||||
@admin.action(description="Export Selected Preferences")
|
||||
def export(self, request: HttpRequest, queryset: QuerySet[WeekPreference]) -> HttpResponse | None:
|
||||
@@ -54,6 +54,19 @@ class WeekPreferenceAdmin(nested_admin.NestedPolymorphicModelAdmin):
|
||||
return []
|
||||
return list_filter
|
||||
|
||||
# Get available mission or HB depending on student course
|
||||
def get_inline_instances(self, request: HttpRequest, obj: WeekPreference | None = None):
|
||||
if hasattr(request.user, "student"):
|
||||
student: Student = request.user.student
|
||||
# Only ATPL students are able to book HourBuilding Missions
|
||||
if student.course and student.course.ctype in (CourseTypes.ATPL, CourseTypes.DISTANCE):
|
||||
return (
|
||||
TrainingInLIne(self.model, self.admin_site),
|
||||
HourBuildingInLine(self.model, self.admin_site),
|
||||
)
|
||||
# All other courses have only training
|
||||
return (TrainingInLIne(self.model, self.admin_site), )
|
||||
|
||||
# If a user is registered as student do not show actions
|
||||
def get_actions(self, request: HttpRequest) -> Dict[str, Any]:
|
||||
actions = super().get_actions(request)
|
||||
|
||||
Reference in New Issue
Block a user