aboutsummaryrefslogtreecommitdiff
path: root/views.py
diff options
context:
space:
mode:
authorAlban Gruin2019-09-01 20:47:49 +0200
committerAlban Gruin2019-09-01 20:47:49 +0200
commit00d70c4d65967987c254c72f8bef5fda991f859b (patch)
tree670b2a78bfeb151096cfa844d6b48559dfc3641b /views.py
parentfe83f55800f78ff6ced9a13cf5a9c22fde0ead12 (diff)
parenta6eaecf48f63c37cf851386a45cd4b25ac3ed1e0 (diff)
Merge branch 'futur'
Diffstat (limited to 'views.py')
-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})