Improved time widget visualization

This commit is contained in:
2025-11-21 18:57:44 +01:00
parent 48ff1d799c
commit 7ad09e21b7
3 changed files with 28 additions and 23 deletions

View File

@@ -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

View File

@@ -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"

View File

@@ -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,