polymorphic #1
@@ -9,7 +9,3 @@ urlpatterns = [
|
|||||||
path('user/', flightslot_user.urls),
|
path('user/', flightslot_user.urls),
|
||||||
path("", lambda r: redirect("/user/")), # la root porta gli utenti nella pagina giusta
|
path("", lambda r: redirect("/user/")), # la root porta gli utenti nella pagina giusta
|
||||||
]
|
]
|
||||||
|
|
||||||
admin.site.site_header = "Flight Scheduler 🛫"
|
|
||||||
admin.site.site_title = "Flight Scheduler 🛫"
|
|
||||||
admin.site.index_title = "Welcome to CantorAir Flight Scheduler Portal"
|
|
||||||
|
|||||||
@@ -32,6 +32,10 @@ flightslot_user = FlightSlotUserSite(name="user_site")
|
|||||||
# registra SOLO i modelli autorizzati
|
# registra SOLO i modelli autorizzati
|
||||||
flightslot_user.register(WeekPreference, WeekPreferenceAdmin)
|
flightslot_user.register(WeekPreference, WeekPreferenceAdmin)
|
||||||
|
|
||||||
|
admin.site.site_header = "Flight Scheduler Admin 🛫"
|
||||||
|
admin.site.site_title = "Flight Scheduler Admin 🛫"
|
||||||
|
admin.site.index_title = "Welcome to CantorAir Flight Scheduler Administrator Portal"
|
||||||
|
|
||||||
admin.site.register(Course, CourseAdmin)
|
admin.site.register(Course, CourseAdmin)
|
||||||
admin.site.register(MissionProfile, MissionProfileAdmin)
|
admin.site.register(MissionProfile, MissionProfileAdmin)
|
||||||
admin.site.register(Student, StudentAdmin)
|
admin.site.register(Student, StudentAdmin)
|
||||||
|
|||||||
@@ -15,29 +15,52 @@ from datetime import date
|
|||||||
class HourBuildingLegForm(forms.ModelForm):
|
class HourBuildingLegForm(forms.ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = HourBuildingLegFlight
|
model = HourBuildingLegFlight
|
||||||
fields = '__all__'
|
fields = "__all__"
|
||||||
widgets = {
|
widgets = {
|
||||||
'time': TimeDurationWidget(show_days=False,
|
"time": TimeDurationWidget(show_days=False,
|
||||||
show_seconds=False)
|
show_seconds=False)
|
||||||
}
|
}
|
||||||
|
|
||||||
# Register your models here.
|
# Register your models here.
|
||||||
class HourBuildingLegBaseInLine(nested_admin.NestedStackedPolymorphicInline):
|
class HourBuildingLegBaseInLine(nested_admin.NestedStackedPolymorphicInline):
|
||||||
model = HourBuildingLegBase
|
model = HourBuildingLegBase
|
||||||
fk_name = 'hb'
|
fk_name = "hb"
|
||||||
verbose_name_plural = "Hour Building Legs"
|
verbose_name_plural = "Hour Building Legs"
|
||||||
|
|
||||||
|
def get_inline_title(self, obj):
|
||||||
|
return "PIPPO"
|
||||||
|
|
||||||
class HourBuildingLegFlightInLine(nested_admin.NestedStackedPolymorphicInline.Child):
|
class HourBuildingLegFlightInLine(nested_admin.NestedStackedPolymorphicInline.Child):
|
||||||
model = HourBuildingLegFlight
|
model = HourBuildingLegFlight
|
||||||
form = HourBuildingLegForm
|
form = HourBuildingLegForm
|
||||||
|
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):
|
class HourBuildingLegStopInLine(nested_admin.NestedStackedPolymorphicInline.Child):
|
||||||
model = HourBuildingLegStop
|
model = HourBuildingLegStop
|
||||||
|
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, )
|
child_inlines = (HourBuildingLegFlightInLine, HourBuildingLegStopInLine, )
|
||||||
|
|
||||||
# If user is a student deny edit permission for week past the current one
|
# If user is a student deny edit permission for week past the current one
|
||||||
def has_change_permission(self, request: HttpRequest, obj: HourBuilding | None = None):
|
def has_change_permission(self, request: HttpRequest, obj: HourBuilding | None = None):
|
||||||
if hasattr(request.user, 'student') and obj:
|
if hasattr(request.user, "student") and obj:
|
||||||
current_week = date.today().isocalendar().week
|
current_week = date.today().isocalendar().week
|
||||||
if not obj.DoesNotExist and current_week > obj.weekpref.week:
|
if not obj.DoesNotExist and current_week > obj.weekpref.week:
|
||||||
return False
|
return False
|
||||||
@@ -49,13 +72,13 @@ class HourBuildingLegBaseInLine(nested_admin.NestedStackedPolymorphicInline):
|
|||||||
|
|
||||||
class HourBuildingInLine(nested_admin.NestedTabularInline):
|
class HourBuildingInLine(nested_admin.NestedTabularInline):
|
||||||
model = HourBuilding
|
model = HourBuilding
|
||||||
extra = 1
|
|
||||||
inlines = (HourBuildingLegBaseInLine,)
|
inlines = (HourBuildingLegBaseInLine,)
|
||||||
fk_name = 'weekpref'
|
extra = 0
|
||||||
verbose_name_plural = "Hour Buildings"
|
|
||||||
max_num = 7
|
max_num = 7
|
||||||
|
fk_name = "weekpref"
|
||||||
|
verbose_name_plural = "Hour Buildings"
|
||||||
formfield_overrides = {
|
formfield_overrides = {
|
||||||
models.CharField: {'widget': TextInput(attrs={'size':'20'})},
|
models.CharField: {"widget": TextInput(attrs={"size":"20"})},
|
||||||
models.TextField: {'widget': Textarea(attrs={'rows':4, 'cols':35})},
|
models.TextField: {"widget": Textarea(attrs={"rows":4, "cols":35})},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
# Generated by Django 5.2.8 on 2025-11-21 16:27
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('flightslot', '0018_hourbuildinglegbase_hourbuildinglegflight_and_more'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='hourbuildinglegstop',
|
||||||
|
name='location',
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='hourbuildinglegflight',
|
||||||
|
name='pax',
|
||||||
|
field=models.CharField(max_length=16, null=True),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='hourbuildinglegbase',
|
||||||
|
name='time',
|
||||||
|
field=models.DurationField(),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='hourbuildinglegflight',
|
||||||
|
name='departure',
|
||||||
|
field=models.CharField(max_length=4),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='hourbuildinglegflight',
|
||||||
|
name='destination',
|
||||||
|
field=models.CharField(max_length=4),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -78,36 +78,51 @@ class HourBuildingLegBase(PolymorphicModel):
|
|||||||
)
|
)
|
||||||
|
|
||||||
time = models.DurationField(
|
time = models.DurationField(
|
||||||
null=False,
|
null=False
|
||||||
default = timedelta(hours=1)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
class HourBuildingLegFlight(HourBuildingLegBase):
|
class HourBuildingLegFlight(HourBuildingLegBase):
|
||||||
departure = models.CharField(
|
departure = models.CharField(
|
||||||
null=False,
|
null=False,
|
||||||
blank=False,
|
blank=False,
|
||||||
default="LILV",
|
|
||||||
max_length=4
|
max_length=4
|
||||||
)
|
)
|
||||||
|
|
||||||
destination = models.CharField(
|
destination = models.CharField(
|
||||||
null=False,
|
null=False,
|
||||||
blank=False,
|
blank=False,
|
||||||
default="LILV",
|
|
||||||
max_length=4
|
max_length=4
|
||||||
)
|
)
|
||||||
|
|
||||||
|
pax = models.CharField(
|
||||||
|
null=True,
|
||||||
|
blank=True,
|
||||||
|
max_length=16,
|
||||||
|
verbose_name="Pax (optional)"
|
||||||
|
)
|
||||||
|
|
||||||
|
class Meta(PolymorphicModel.Meta):
|
||||||
|
verbose_name = "Flight leg"
|
||||||
|
verbose_name_plural = "Flight legs"
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"Flight Leg: {self.departure} -> {self.destination}"
|
return f"{self.departure} -> {self.destination}"
|
||||||
|
|
||||||
|
def save(self, *args, **kwargs):
|
||||||
|
self.departure = self.departure.capitalize().strip()
|
||||||
|
self.destination = self.destination.capitalize().strip()
|
||||||
|
super().save(*args, **kwargs)
|
||||||
|
|
||||||
class HourBuildingLegStop(HourBuildingLegBase):
|
class HourBuildingLegStop(HourBuildingLegBase):
|
||||||
location = models.CharField(
|
|
||||||
null=False,
|
|
||||||
blank=False,
|
|
||||||
default="LILV",
|
|
||||||
max_length=4
|
|
||||||
)
|
|
||||||
|
|
||||||
refuel = models.BooleanField(
|
refuel = models.BooleanField(
|
||||||
default=False
|
default=False
|
||||||
)
|
)
|
||||||
|
|
||||||
|
class Meta(PolymorphicModel.Meta):
|
||||||
|
verbose_name = "Stop"
|
||||||
|
verbose_name_plural = "Stops"
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f"Refuel" if self.refuel else f"No Refuel"
|
||||||
|
|
||||||
@@ -51,7 +51,7 @@ class Student(models.Model):
|
|||||||
|
|
||||||
# Override save method to add user for login upon Student creation
|
# Override save method to add user for login upon Student creation
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
creating = self.pk is None
|
creating: bool = self.pk is None
|
||||||
super().save(*args, **kwargs)
|
super().save(*args, **kwargs)
|
||||||
if creating and not self.user:
|
if creating and not self.user:
|
||||||
username = f"{self.name.lower()}.{self.surname.lower()}"
|
username = f"{self.name.lower()}.{self.surname.lower()}"
|
||||||
@@ -68,7 +68,7 @@ class Student(models.Model):
|
|||||||
username=username,
|
username=username,
|
||||||
email=self.email,
|
email=self.email,
|
||||||
password=self.default_password(),
|
password=self.default_password(),
|
||||||
is_staff=True
|
is_staff=True # allows access to admin page
|
||||||
)
|
)
|
||||||
|
|
||||||
student_group, _ = Group.objects.get_or_create(name="StudentGroup")
|
student_group, _ = Group.objects.get_or_create(name="StudentGroup")
|
||||||
|
|||||||
6
cntmanage/poetry.lock
generated
6
cntmanage/poetry.lock
generated
@@ -2,14 +2,14 @@
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "asgiref"
|
name = "asgiref"
|
||||||
version = "3.10.0"
|
version = "3.11.0"
|
||||||
description = "ASGI specs, helper code, and adapters"
|
description = "ASGI specs, helper code, and adapters"
|
||||||
optional = false
|
optional = false
|
||||||
python-versions = ">=3.9"
|
python-versions = ">=3.9"
|
||||||
groups = ["main"]
|
groups = ["main"]
|
||||||
files = [
|
files = [
|
||||||
{file = "asgiref-3.10.0-py3-none-any.whl", hash = "sha256:aef8a81283a34d0ab31630c9b7dfe70c812c95eba78171367ca8745e88124734"},
|
{file = "asgiref-3.11.0-py3-none-any.whl", hash = "sha256:1db9021efadb0d9512ce8ffaf72fcef601c7b73a8807a1bb2ef143dc6b14846d"},
|
||||||
{file = "asgiref-3.10.0.tar.gz", hash = "sha256:d89f2d8cd8b56dada7d52fa7dc8075baa08fb836560710d38c292a7a3f78c04e"},
|
{file = "asgiref-3.11.0.tar.gz", hash = "sha256:13acff32519542a1736223fb79a715acdebe24286d98e8b164a73085f40da2c4"},
|
||||||
]
|
]
|
||||||
|
|
||||||
[package.extras]
|
[package.extras]
|
||||||
|
|||||||
Reference in New Issue
Block a user