aboutsummaryrefslogtreecommitdiff
path: root/models.py
diff options
context:
space:
mode:
authorAlban Gruin2017-01-27 21:18:12 +0100
committerAlban Gruin2017-01-27 21:18:12 +0100
commit033e1e78b2038e5d9dfca8960a939a0bb3f1308e (patch)
tree0b3f827383e30751a5ee9f6788c1d42176c7809a /models.py
parent98a7494b6f930490e62cfc134f23d69b32203977 (diff)
Revert "Fonction pour récupérer l'année et la semaine d'un cours directement depuis le manager"
This reverts commit 98a7494b6f930490e62cfc134f23d69b32203977.
Diffstat (limited to 'models.py')
-rw-r--r--models.py19
1 files changed, 2 insertions, 17 deletions
diff --git a/models.py b/models.py
index 64fb675..62274d2 100644
--- a/models.py
+++ b/models.py
@@ -1,7 +1,6 @@
-from django.db import connection, models
+from django.db import models
from django.db.models import Q
-from django.db.models.expressions import RawSQL
-from django.db.models.functions import Extract, ExtractYear
+from django.db.models.functions import Extract
from django.utils.text import slugify
import hashlib
@@ -112,23 +111,9 @@ class Room(models.Model):
class CourseManager(models.Manager):
- def __get_weeks(self, qs):
- extractYear = ExtractYear("begin")
-
- if connection.vendor == "postgresql":
- return qs.annotate(week=ExtractWeek("begin"), year=extractYear)
- else:
- return qs.annotate(week=RawSQL("""cast(strftime("%%W", "begin") as integer)""", []), year=extractYear)
-
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, **filters).order_by("begin")
- def get_weeks(self):
- return self.__get_weeks(self.get_queryset())
-
- def get_courses_for_group_and_weeks(self, group, **filters):
- qs = self.get_courses_for_group(group, **filters)
- return self.__get_weeks(qs)
class Course(models.Model):
objects = CourseManager()