aboutsummaryrefslogtreecommitdiff
path: root/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'models.py')
-rw-r--r--models.py54
1 files changed, 41 insertions, 13 deletions
diff --git a/models.py b/models.py
index b1d6d27..4be7ef5 100644
--- a/models.py
+++ b/models.py
@@ -48,7 +48,8 @@ class Year(SlugModel):
class Timetable(SlugModel):
- year = models.ForeignKey(Year, on_delete=models.CASCADE, verbose_name="année")
+ year = models.ForeignKey(Year, on_delete=models.CASCADE,
+ verbose_name="année")
name = models.CharField(max_length=64, verbose_name="nom")
url = models.URLField(max_length=255, verbose_name="URL")
slug = models.SlugField(max_length=64, default="")
@@ -65,26 +66,36 @@ class Timetable(SlugModel):
class GroupManager(Manager):
def get_relevant_groups(self, *args, **criteria):
- return self.get_queryset().filter(*args, **criteria).annotate(children_count=Count("children")).filter(children_count=0)
+ return self.get_queryset().filter(*args, **criteria) \
+ .annotate(children_count=Count("children")) \
+ .filter(children_count=0)
class Group(models.Model):
objects = GroupManager()
name = models.CharField(max_length=255, verbose_name="nom")
- celcat_name = models.CharField(max_length=255, verbose_name="nom dans Celcat")
- timetable = models.ForeignKey(Timetable, on_delete=models.CASCADE, verbose_name="emploi du temps")
+ celcat_name = models.CharField(max_length=255,
+ verbose_name="nom dans Celcat")
+ timetable = models.ForeignKey(Timetable, on_delete=models.CASCADE,
+ verbose_name="emploi du temps")
mention = models.CharField(max_length=128)
- subgroup = models.CharField(max_length=1, verbose_name="sous-groupe", null=True)
+ subgroup = models.CharField(max_length=1, verbose_name="sous-groupe",
+ null=True)
td = models.IntegerField(verbose_name="groupe de TD", null=True)
tp = models.IntegerField(verbose_name="groupe de TP", null=True)
- parent = models.ForeignKey("self", verbose_name="groupe parent", null=True, default=None, related_name="children")
+ parent = models.ForeignKey("self", verbose_name="groupe parent", null=True,
+ default=None, related_name="children")
slug = models.SlugField(max_length=64, default="")
def corresponds_to(self, timetable_id, mention, subgroup, td, tp):
- return self.timetable.id == timetable_id and self.mention.startswith(mention) and (self.subgroup == subgroup or self.subgroup is None) and (self.td == td or self.td is None or td is None) and (self.tp == tp or self.tp is None or tp is None)
+ return self.timetable.id == timetable_id and \
+ self.mention.startswith(mention) and \
+ (self.subgroup == subgroup or self.subgroup is None) and \
+ (self.td == td or self.td is None or td is None) and \
+ (self.tp == tp or self.tp is None or tp is None)
@property
def group_info(self):
@@ -104,7 +115,9 @@ class Group(models.Model):
class Meta:
index_together = ("mention", "subgroup", "td", "tp",)
- unique_together = (("name", "timetable",), ("celcat_name", "timetable",), ("slug", "timetable",),)
+ unique_together = (("name", "timetable",),
+ ("celcat_name", "timetable",),
+ ("slug", "timetable",),)
verbose_name = "groupe"
verbose_name_plural = "groupes"
@@ -124,18 +137,32 @@ class Room(models.Model):
class CourseManager(Manager):
def get_courses_for_group(self, group, **criteria):
- return self.get_queryset().filter(Q(groups__td__isnull=True) | Q(groups__td=group.td), Q(groups__tp__isnull=True) | Q(groups__tp=group.tp), Q(groups__subgroup__isnull=True) | Q(groups__subgroup=group.subgroup), groups__mention=group.mention, timetable=group.timetable, **criteria).order_by("begin")
+ return self.get_queryset() \
+ .filter(Q(groups__td__isnull=True) | Q(groups__td=group.td),
+ Q(groups__tp__isnull=True) | Q(groups__tp=group.tp),
+ Q(groups__subgroup__isnull=True) | \
+ Q(groups__subgroup=group.subgroup),
+ groups__mention=group.mention,
+ timetable=group.timetable, **criteria) \
+ .order_by("begin")
def get_weeks(self, **criteria):
- return self.get_queryset().filter(**criteria).order_by("groups__name", "year", "week").annotate(_=Count(("groups", "year", "week", "begin")), year=ExtractYear("begin"), week=ExtractWeek("begin"))
+ return self.get_queryset() \
+ .filter(**criteria) \
+ .order_by("groups__name", "year", "week") \
+ .annotate(_=Count(("groups", "year", "week", "begin")),
+ year=ExtractYear("begin"),
+ week=ExtractWeek("begin"))
class Course(models.Model):
objects = CourseManager()
name = models.CharField(max_length=255, verbose_name="nom", null=True)
- type_ = models.CharField(name="type", max_length=255, verbose_name="type de cours", null=True)
- timetable = models.ForeignKey(Timetable, on_delete=models.CASCADE, verbose_name="emploi du temps")
+ type_ = models.CharField(name="type", max_length=255,
+ verbose_name="type de cours", null=True)
+ timetable = models.ForeignKey(Timetable, on_delete=models.CASCADE,
+ verbose_name="emploi du temps")
notes = models.TextField(verbose_name="remarques", blank=True, null=True)
groups = models.ManyToManyField(Group, verbose_name="groupes")
@@ -144,7 +171,8 @@ class Course(models.Model):
begin = models.DateTimeField(verbose_name="début du cours", db_index=True)
end = models.DateTimeField(verbose_name="fin du cours")
- last_update = models.DateTimeField(verbose_name="dernière mise à jour", default=timezone.now)
+ last_update = models.DateTimeField(verbose_name="dernière mise à jour",
+ default=timezone.now)
def __str__(self):
return self.name