Renamed Project to cntmanage
This commit is contained in:
9
cntmanage/flightslot/models/aircrafts.py
Normal file
9
cntmanage/flightslot/models/aircrafts.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.db import models
|
||||
|
||||
class AircraftTypes(models.TextChoices):
|
||||
C152 = "C152", _("Cessna 152")
|
||||
P208 = "P208", _("Tecnam P2008")
|
||||
PA28 = "PA28", _("Piper PA28R")
|
||||
C182 = "C182", _("Cessna 182Q")
|
||||
P210 = "TWEN", _("Tecnam P2010")
|
||||
52
cntmanage/flightslot/models/courses.py
Normal file
52
cntmanage/flightslot/models/courses.py
Normal file
@@ -0,0 +1,52 @@
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.db import models
|
||||
from datetime import date
|
||||
from colorfield.fields import ColorField
|
||||
|
||||
class CourseTypes(models.TextChoices):
|
||||
FI = "FI", _("FI")
|
||||
PPL = "PPL", _("PPL")
|
||||
ATPL = "ATPL", _("ATPL")
|
||||
DISTANCE = "DL", _("DISTANCE")
|
||||
OTHER = "OTHER",_("OTHER")
|
||||
|
||||
|
||||
class Course(models.Model):
|
||||
# Add colors according to table from Alessia
|
||||
COLOR_PALETTE = [
|
||||
("#ffffff","WHITE"),
|
||||
("#ff0000", "RED"),
|
||||
("#00ff00", "GREEN"),
|
||||
("#0000ff", "BLUE")
|
||||
]
|
||||
|
||||
id = models.AutoField(
|
||||
primary_key=True
|
||||
)
|
||||
|
||||
ctype = models.CharField(
|
||||
null=False,
|
||||
choices=CourseTypes,
|
||||
verbose_name=_("Course Type")
|
||||
)
|
||||
|
||||
cnumber = models.PositiveSmallIntegerField(
|
||||
null=False,
|
||||
default=date.today().year,
|
||||
verbose_name=_("Course Number")
|
||||
)
|
||||
|
||||
year = models.PositiveSmallIntegerField(
|
||||
null=False,
|
||||
default=date.today().year,
|
||||
verbose_name=_("Year")
|
||||
)
|
||||
|
||||
color = ColorField (
|
||||
samples=COLOR_PALETTE,
|
||||
verbose_name=_("Binder Color")
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.ctype}-{self.cnumber}"
|
||||
|
||||
103
cntmanage/flightslot/models/hourbuildings.py
Normal file
103
cntmanage/flightslot/models/hourbuildings.py
Normal file
@@ -0,0 +1,103 @@
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.db import models
|
||||
from datetime import timedelta
|
||||
|
||||
from ..models.weekpref import WeekPreference
|
||||
from ..models.aircrafts import AircraftTypes
|
||||
|
||||
|
||||
class HourBuilding(models.Model):
|
||||
id = models.BigAutoField(
|
||||
primary_key=True
|
||||
)
|
||||
|
||||
weekpref = models.ForeignKey(
|
||||
WeekPreference,
|
||||
null=False,
|
||||
on_delete=models.CASCADE
|
||||
)
|
||||
|
||||
aircraft = models.CharField(
|
||||
null=False,
|
||||
choices=AircraftTypes
|
||||
)
|
||||
|
||||
monday = models.BooleanField(
|
||||
default=True,
|
||||
null=False
|
||||
)
|
||||
|
||||
tuesday = models.BooleanField(
|
||||
default=True,
|
||||
null=False
|
||||
)
|
||||
|
||||
wednesday = models.BooleanField(
|
||||
default=True,
|
||||
null=False
|
||||
)
|
||||
|
||||
thursday = models.BooleanField(
|
||||
default=True,
|
||||
null=False
|
||||
)
|
||||
|
||||
friday = models.BooleanField(
|
||||
default=True,
|
||||
null=False
|
||||
)
|
||||
|
||||
saturday = models.BooleanField(
|
||||
default=True,
|
||||
null=False
|
||||
)
|
||||
|
||||
sunday = models.BooleanField(
|
||||
default=True,
|
||||
null=False
|
||||
)
|
||||
|
||||
notes = models.TextField(
|
||||
max_length=140,
|
||||
null=True,
|
||||
blank=True
|
||||
)
|
||||
|
||||
class HourBuildingLeg(models.Model):
|
||||
id = models.BigAutoField(
|
||||
primary_key=True
|
||||
)
|
||||
|
||||
hb = models.ForeignKey(
|
||||
HourBuilding,
|
||||
on_delete=models.CASCADE
|
||||
)
|
||||
|
||||
departure = models.CharField(
|
||||
null=False,
|
||||
blank=False,
|
||||
default="LILV",
|
||||
max_length=4
|
||||
)
|
||||
|
||||
destination = models.CharField(
|
||||
null=False,
|
||||
blank=False,
|
||||
default="LILV",
|
||||
max_length=4
|
||||
)
|
||||
|
||||
time = models.DurationField(
|
||||
null=False,
|
||||
default = timedelta(hours=1)
|
||||
)
|
||||
|
||||
stop = models.BooleanField(
|
||||
default=False
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
if self.stop:
|
||||
return "Refuelling Stop"
|
||||
else:
|
||||
return f"Flight Leg: {self.departure} -> {self.destination}"
|
||||
109
cntmanage/flightslot/models/missions.py
Normal file
109
cntmanage/flightslot/models/missions.py
Normal file
@@ -0,0 +1,109 @@
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.db import models
|
||||
from datetime import timedelta
|
||||
|
||||
from ..models.weekpref import WeekPreference
|
||||
|
||||
class MissionType(models.TextChoices):
|
||||
OTHER = "OTHER", _("OTHER")
|
||||
PPL = "PPL", _("PPL")
|
||||
IR = "IR", _("IR")
|
||||
MEP = "MEP", _("MEP")
|
||||
CPL = "CPL", _("CPL")
|
||||
FI = "FI", _("FI")
|
||||
PC = "PC", _("PC")
|
||||
CHK = "CHK", _("CHK_6M")
|
||||
|
||||
class MissionProfile(models.Model):
|
||||
id = models.AutoField(
|
||||
primary_key=True
|
||||
)
|
||||
|
||||
mtype = models.CharField(
|
||||
null=False,
|
||||
default=MissionType.PPL,
|
||||
choices=MissionType,
|
||||
verbose_name="Mission Type"
|
||||
)
|
||||
|
||||
mnum = models.PositiveSmallIntegerField(
|
||||
null=True,
|
||||
default=0,
|
||||
verbose_name="Mission Number"
|
||||
)
|
||||
|
||||
duration = models.DurationField(
|
||||
null=False,
|
||||
default=timedelta(hours=1)
|
||||
)
|
||||
|
||||
notes = models.TextField(
|
||||
max_length=140,
|
||||
null=True,
|
||||
blank=True
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.mtype} {self.mnum}"
|
||||
|
||||
class Training(models.Model):
|
||||
id = models.BigAutoField(
|
||||
primary_key=True
|
||||
)
|
||||
|
||||
weekpref = models.ForeignKey(
|
||||
WeekPreference,
|
||||
null=False,
|
||||
on_delete=models.CASCADE
|
||||
)
|
||||
|
||||
mission = models.ForeignKey(
|
||||
MissionProfile,
|
||||
null=True,
|
||||
on_delete=models.CASCADE
|
||||
)
|
||||
|
||||
monday = models.BooleanField(
|
||||
default=True,
|
||||
null=False
|
||||
)
|
||||
|
||||
tuesday = models.BooleanField(
|
||||
default=True,
|
||||
null=False
|
||||
)
|
||||
|
||||
wednesday = models.BooleanField(
|
||||
default=True,
|
||||
null=False
|
||||
)
|
||||
|
||||
thursday = models.BooleanField(
|
||||
default=True,
|
||||
null=False
|
||||
)
|
||||
|
||||
friday = models.BooleanField(
|
||||
default=True,
|
||||
null=False
|
||||
)
|
||||
|
||||
saturday = models.BooleanField(
|
||||
default=True,
|
||||
null=False
|
||||
)
|
||||
|
||||
sunday = models.BooleanField(
|
||||
default=True,
|
||||
null=False
|
||||
)
|
||||
|
||||
notes = models.TextField(
|
||||
max_length=140,
|
||||
null=True,
|
||||
blank=True
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.mission}"
|
||||
|
||||
80
cntmanage/flightslot/models/students.py
Normal file
80
cntmanage/flightslot/models/students.py
Normal file
@@ -0,0 +1,80 @@
|
||||
from django.db import models
|
||||
from django.contrib.auth.models import User, Group
|
||||
|
||||
from ..models.courses import Course
|
||||
|
||||
class Student(models.Model):
|
||||
id = models.AutoField(
|
||||
primary_key=True
|
||||
)
|
||||
|
||||
email = models.EmailField(
|
||||
null=False,
|
||||
db_index=True
|
||||
)
|
||||
|
||||
phone = models.CharField(
|
||||
null=True,
|
||||
max_length=16
|
||||
)
|
||||
|
||||
name = models.CharField(
|
||||
null=False,
|
||||
max_length=32
|
||||
)
|
||||
|
||||
surname = models.CharField(
|
||||
null=False,
|
||||
max_length=32
|
||||
)
|
||||
|
||||
course = models.ForeignKey(
|
||||
Course,
|
||||
on_delete=models.DO_NOTHING,
|
||||
null=True
|
||||
)
|
||||
|
||||
active = models.BooleanField(
|
||||
null=False,
|
||||
default=True
|
||||
)
|
||||
|
||||
user = models.OneToOneField(
|
||||
User,
|
||||
on_delete=models.CASCADE,
|
||||
null=True,
|
||||
blank=True
|
||||
)
|
||||
|
||||
def default_password(self) -> str:
|
||||
return f"{self.name.lower()[0]}{self.surname.lower()}{self.id}"
|
||||
|
||||
# Override save method to add user for login upon Student creation
|
||||
def save(self, *args, **kwargs):
|
||||
creating = self.pk is None
|
||||
super().save(*args, **kwargs)
|
||||
if creating and not self.user:
|
||||
username = f"{self.name.lower()}.{self.surname.lower()}"
|
||||
# Avoid username conflict with progressive number
|
||||
base_username = username
|
||||
counter = 1
|
||||
while User.objects.filter(username=username).exists():
|
||||
username = f"{base_username}{counter}"
|
||||
counter += 1
|
||||
# Create user
|
||||
user = User.objects.create_user(
|
||||
first_name=self.name,
|
||||
last_name=self.surname,
|
||||
username=username,
|
||||
email=self.email,
|
||||
password=self.default_password(),
|
||||
is_staff=True
|
||||
)
|
||||
|
||||
student_group, _ = Group.objects.get_or_create(name="StudentGroup")
|
||||
user.groups.add(student_group)
|
||||
self.user = user
|
||||
self.save()
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.surname} {self.name[0]}. => {self.course}"
|
||||
28
cntmanage/flightslot/models/weekpref.py
Normal file
28
cntmanage/flightslot/models/weekpref.py
Normal file
@@ -0,0 +1,28 @@
|
||||
from django.db import models
|
||||
from datetime import date
|
||||
|
||||
from ..models.students import Student
|
||||
|
||||
class WeekPreference(models.Model):
|
||||
id = models.BigAutoField(
|
||||
primary_key=True
|
||||
)
|
||||
|
||||
week = models.PositiveSmallIntegerField(
|
||||
null=False,
|
||||
db_index=True,
|
||||
db_default=date.today().isocalendar().week,
|
||||
auto_created=True,
|
||||
verbose_name="Week Number"
|
||||
)
|
||||
|
||||
student = models.ForeignKey(
|
||||
Student,
|
||||
null=False,
|
||||
db_index=True,
|
||||
on_delete=models.DO_NOTHING,
|
||||
verbose_name="Student Selection"
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return f"Week {self.week} - {self.student.surname} {self.student.name[0]}."
|
||||
Reference in New Issue
Block a user