aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlban Gruin2017-02-11 13:47:38 +0100
committerAlban Gruin2017-02-11 13:47:38 +0100
commitff25e2dc285c423f4c40a83deb89a56ee62b15a9 (patch)
tree888b5189c582371417ddcba02cbf5e883fa0e36e
parent26a132d5d1fdb7fc9da827bbc9d5e409834fb954 (diff)
Nettoyage du code de CourseManagerdev/db-groupby
-rw-r--r--models.py14
1 files changed, 5 insertions, 9 deletions
diff --git a/models.py b/models.py
index 68e1e84..1e96a88 100644
--- a/models.py
+++ b/models.py
@@ -144,21 +144,17 @@ class Room(models.Model):
class CourseManager(Manager):
- def __get_weeks(self, qs):
- qs = qs.order_by("groups__name", "year", "week").annotate(_=Count(("groups", "year", "week", "begin")), year=ExtractYear("begin"))
+ def get_courses_for_group(self, group, **filters):
+ 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), groups__mention=group.mention, groups__subgroup=group.subgroup, timetable=group.timetable, **filters).order_by("begin")
+
+ def get_weeks(self, **criteria):
+ qs = self.get_queryset().filter(**criteria).order_by("groups__name", "year", "week").annotate(_=Count(("groups", "year", "week", "begin")), year=ExtractYear("begin"))
if connection.vendor == "postgresql":
return qs.annotate(week=ExtractWeek("begin"))
else:
return qs.annotate(week=RawSQL("""cast(strftime("%%W", "begin") as integer)""", []))
- def get_courses_for_group(self, group, **filters):
- 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), groups__mention=group.mention, groups__subgroup=group.subgroup, timetable=group.timetable, **filters).order_by("begin")
-
- def get_weeks(self, **criteria):
- qs = self.get_queryset().filter(**criteria)
- return self.__get_weeks(qs)
-
class Course(models.Model):
objects = CourseManager()