From 7ad09e21b7096ddd37af66fc8530f7bdeeb602e3 Mon Sep 17 00:00:00 2001 From: Emanuele Date: Fri, 21 Nov 2025 18:57:44 +0100 Subject: [PATCH] Improved time widget visualization --- .../flightslot/admins/hourbuilding_adm.py | 43 ++++++++++--------- cntmanage/flightslot/models/hourbuildings.py | 2 + cntmanage/flightslot/models/students.py | 6 +-- 3 files changed, 28 insertions(+), 23 deletions(-) diff --git a/cntmanage/flightslot/admins/hourbuilding_adm.py b/cntmanage/flightslot/admins/hourbuilding_adm.py index 7c6f07c..30dbb4c 100644 --- a/cntmanage/flightslot/admins/hourbuilding_adm.py +++ b/cntmanage/flightslot/admins/hourbuilding_adm.py @@ -12,13 +12,32 @@ from ..models.weekpref import WeekPreference from datetime import date -class HourBuildingLegForm(forms.ModelForm): +class HourBuildingLegFlightForm(forms.ModelForm): class Meta: model = HourBuildingLegFlight fields = "__all__" widgets = { "time": TimeDurationWidget(show_days=False, - show_seconds=False) + show_seconds=False, + attrs={ + "style": ( + "margin-right:5px; margin-left:5px; width:40px; min:0; max:5" + ) + }) + } + +class HourBuildingLegStopForm(forms.ModelForm): + class Meta: + model = HourBuildingLegStop + fields = "__all__" + widgets = { + "time": TimeDurationWidget(show_days=False, + show_seconds=False, + attrs={ + "style": ( + "margin-right:5px; margin-left:5px; width:40px;" + ) + }) } # Register your models here. @@ -26,36 +45,20 @@ class HourBuildingLegBaseInLine(nested_admin.NestedStackedPolymorphicInline): model = HourBuildingLegBase fk_name = "hb" verbose_name_plural = "Hour Building Legs" - - def get_inline_title(self, obj): - return "PIPPO" class HourBuildingLegFlightInLine(nested_admin.NestedStackedPolymorphicInline.Child): model = HourBuildingLegFlight - form = HourBuildingLegForm + form = HourBuildingLegFlightForm fk_name = "hourbuildinglegbase_ptr" fields = ("departure", "time", "destination", "pax", ) hide_title = True - - def get_inline_title(self, obj: HourBuildingLegFlight | None = None) -> str: - if obj: - return f"Flight Leg:" - else: - return f"New Flight Leg" class HourBuildingLegStopInLine(nested_admin.NestedStackedPolymorphicInline.Child): model = HourBuildingLegStop + form = HourBuildingLegFlightForm fk_name = "hourbuildinglegbase_ptr" fields = ("time", "refuel", ) - hide_title = True - - def get_inline_title(self, obj: HourBuildingLegStop | None = None) -> str: - if obj: - return f"Stop at:" - else: - return f"New Stop" - child_inlines = (HourBuildingLegFlightInLine, HourBuildingLegStopInLine, ) # If user is a student deny edit permission for week past the current one diff --git a/cntmanage/flightslot/models/hourbuildings.py b/cntmanage/flightslot/models/hourbuildings.py index 2259c68..cc1b60f 100644 --- a/cntmanage/flightslot/models/hourbuildings.py +++ b/cntmanage/flightslot/models/hourbuildings.py @@ -101,6 +101,7 @@ class HourBuildingLegFlight(HourBuildingLegBase): verbose_name="Pax (optional)" ) + # Change displayed name in the inline form class Meta(PolymorphicModel.Meta): verbose_name = "Flight leg" verbose_name_plural = "Flight legs" @@ -119,6 +120,7 @@ class HourBuildingLegStop(HourBuildingLegBase): default=False ) + # Change displayed name in the inline form class Meta(PolymorphicModel.Meta): verbose_name = "Stop" verbose_name_plural = "Stops" diff --git a/cntmanage/flightslot/models/students.py b/cntmanage/flightslot/models/students.py index 5bcd21d..2582a01 100644 --- a/cntmanage/flightslot/models/students.py +++ b/cntmanage/flightslot/models/students.py @@ -54,15 +54,15 @@ class Student(models.Model): creating: bool = self.pk is None super().save(*args, **kwargs) if creating and not self.user: - username = f"{self.name.lower()}.{self.surname.lower()}" + username: str = f"{self.name.lower()}.{self.surname.lower()}" # Avoid username conflict with progressive number base_username = username - counter = 1 + counter: int = 1 while User.objects.filter(username=username).exists(): username = f"{base_username}{counter}" counter += 1 # Create user - user = User.objects.create_user( + user: User = User.objects.create_user( first_name=self.name, last_name=self.surname, username=username,