aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--views.py16
1 files changed, 6 insertions, 10 deletions
diff --git a/views.py b/views.py
index de38f35..7bb3916 100644
--- a/views.py
+++ b/views.py
@@ -17,7 +17,8 @@ import datetime
from django.db import connection
from django.db.models import Count, Max
-from django.db.models.functions import ExtractWeek, ExtractYear, Length
+from django.db.models.functions import ExtractWeek, ExtractYear, Length, \
+ TruncWeek
from django.http import Http404
from django.shortcuts import get_object_or_404, render
from django.utils import timezone
@@ -32,7 +33,6 @@ import edt
if connection.vendor == "postgresql":
from django.contrib.postgres.aggregates import ArrayAgg
- from django.db.models.expressions import RawSQL
def index(request):
@@ -195,9 +195,8 @@ def rooms(request):
rooms = Room.objects.filter(course__begin__gte=start,
course__begin__lt=end) \
.order_by("name") \
- .annotate(weeks=ArrayAgg(
- RawSQL("date_trunc('week', edt_course.begin)",
- []), distinct=True))
+ .annotate(weeks=ArrayAgg(TruncWeek("week"),
+ distinct=True))
return render(request, "room_list.html", {"elements": rooms})
@@ -210,8 +209,7 @@ def rooms(request):
rooms = Room.objects.filter(course__begin__gte=start,
course__begin__lt=end) \
.order_by("name") \
- .annotate(year=ExtractYear("course__begin"),
- week=ExtractWeek("course__begin"),
+ .annotate(week=TruncWeek("course__begin"),
c=Count("*"))
# Regroupement des semaines dans une liste de chaque objet salle
@@ -226,10 +224,8 @@ def rooms(request):
room.weeks = []
rooms_weeks.append(room)
- # On récupère le premier jour de la semaine
- date, _ = get_week(room.year, room.week)
# Et on le rajoute dans la liste des semaines de la salle.
- rooms_weeks[-1].weeks.append(date)
+ rooms_weeks[-1].weeks.append(room.week)
# Rendu de la page.
return render(request, "room_list.html", {"elements": rooms_weeks})