diff --git a/cntmanage/flightslot/admins/hourbuilding_adm.py b/cntmanage/flightslot/admins/hourbuilding_adm.py index 6a35c20..d49c28a 100644 --- a/cntmanage/flightslot/admins/hourbuilding_adm.py +++ b/cntmanage/flightslot/admins/hourbuilding_adm.py @@ -2,8 +2,8 @@ import nested_admin from django import forms from django.db import models -from django.forms import TextInput, Textarea from django.http import HttpRequest +from django.forms import TextInput, Textarea from durationwidget.widgets import TimeDurationWidget diff --git a/cntmanage/flightslot/admins/training_adm.py b/cntmanage/flightslot/admins/training_adm.py index 11aef85..96f539d 100644 --- a/cntmanage/flightslot/admins/training_adm.py +++ b/cntmanage/flightslot/admins/training_adm.py @@ -45,6 +45,8 @@ class TrainingInLIne(nested_admin.NestedTabularInline): Q(mtype=MissionTypes.CPL) | \ Q(mtype=MissionTypes.CHK) kwargs["queryset"] = MissionProfile.objects.filter(q).order_by("id") + case CourseTypes.FI: + kwargs["queryset"] = MissionProfile.objects.filter(mtype=MissionTypes.FI).order_by("mnum") case _: pass return super().formfield_for_foreignkey(db_field, request, **kwargs) diff --git a/cntmanage/flightslot/admins/weekpref_adm.py b/cntmanage/flightslot/admins/weekpref_adm.py index 3a1849c..ae5b221 100644 --- a/cntmanage/flightslot/admins/weekpref_adm.py +++ b/cntmanage/flightslot/admins/weekpref_adm.py @@ -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) diff --git a/cntmanage/flightslot/migrations/0029_alter_course_ctype.py b/cntmanage/flightslot/migrations/0029_alter_course_ctype.py new file mode 100644 index 0000000..9532888 --- /dev/null +++ b/cntmanage/flightslot/migrations/0029_alter_course_ctype.py @@ -0,0 +1,18 @@ +# Generated by Django 5.2.8 on 2025-12-05 16:57 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('flightslot', '0028_alter_availability_options'), + ] + + operations = [ + migrations.AlterField( + model_name='course', + name='ctype', + field=models.CharField(choices=[('FI', 'FI'), ('PPL', 'PPL'), ('ATPL', 'ATPL'), ('DL', 'DISTANCE'), ('DL_VOLO', 'DISTANCE_VOLO'), ('OTHER', 'OTHER')], verbose_name='Course Type'), + ), + ] diff --git a/cntmanage/flightslot/models/courses.py b/cntmanage/flightslot/models/courses.py index b9ab541..2003eb5 100644 --- a/cntmanage/flightslot/models/courses.py +++ b/cntmanage/flightslot/models/courses.py @@ -8,6 +8,7 @@ class CourseTypes(models.TextChoices): PPL = "PPL", _("PPL") ATPL = "ATPL", _("ATPL") DISTANCE = "DL", _("DISTANCE") + DISTANCE_VOLO = "DL_VOLO", _("DISTANCE_VOLO") OTHER = "OTHER",_("OTHER") class Course(models.Model): diff --git a/cntmanage/flightslot/models/hourbuildings.py b/cntmanage/flightslot/models/hourbuildings.py index c92af17..263042a 100644 --- a/cntmanage/flightslot/models/hourbuildings.py +++ b/cntmanage/flightslot/models/hourbuildings.py @@ -117,6 +117,8 @@ class HourBuildingLegFlight(HourBuildingLegBase): def save(self, *args, **kwargs): self.departure = self.departure.upper().strip() self.destination = self.destination.upper().strip() + if self.pax: + self.pax = " ".join(c.capitalize() for c in self.pax.split()) super().save(*args, **kwargs) def __str__(self):