aboutsummaryrefslogtreecommitdiff
path: root/models.py
diff options
context:
space:
mode:
authorAlban Gruin2017-04-05 14:54:17 +0200
committerAlban Gruin2017-04-05 14:54:17 +0200
commit21b0f53454e60c672f501389f225bb76d062e33c (patch)
treee633bb3290579f50e470c597f849879ee2591fec /models.py
parent7a470357a430a61fd61e5601fd2dde37f13bc646 (diff)
Django 1.11 est la version minimale requise.
Suppression de la classe ExtractWeek maison en faveur de celle fournie par Django 1.11. Modification de la requête de récupération des semaines pour effacer le code spécifique à PostgreSQL et SQLite. Mise à jour du README pour refléter ces changements
Diffstat (limited to 'models.py')
-rw-r--r--models.py13
1 files changed, 2 insertions, 11 deletions
diff --git a/models.py b/models.py
index 3e48622..876160b 100644
--- a/models.py
+++ b/models.py
@@ -17,7 +17,7 @@
from django.db import connection, models
from django.db.models import Count, Manager, Q
from django.db.models.expressions import RawSQL
-from django.db.models.functions import Extract, ExtractYear
+from django.db.models.functions import ExtractWeek, ExtractYear
from django.utils.text import slugify
from .utils import parse_group
@@ -26,10 +26,6 @@ import hashlib
import os
-class ExtractWeek(Extract):
- lookup_name = "week"
-
-
class Timetable(models.Model):
name = models.CharField(max_length=64, unique=True, verbose_name="nom")
url = models.URLField(max_length=255, unique=True, verbose_name="URL")
@@ -137,12 +133,7 @@ class CourseManager(Manager):
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, **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)""", []))
+ 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):