aboutsummaryrefslogtreecommitdiff
path: root/views.py
diff options
context:
space:
mode:
authorAlban Gruin2017-11-18 13:35:37 +0100
committerAlban Gruin2017-11-27 12:11:30 +0100
commit959afb011f5e98e56f88a455228eab32579c9433 (patch)
tree16f44cb0d076796360d7d5f79581f3e489c04a39 /views.py
parent1b0fbf29a484b16de31ac5df1b3fded39be95e97 (diff)
Contenu de la page des emplois du temps
Diffstat (limited to 'views.py')
-rw-r--r--views.py37
1 files changed, 33 insertions, 4 deletions
diff --git a/views.py b/views.py
index c008052..9047329 100644
--- a/views.py
+++ b/views.py
@@ -15,12 +15,12 @@
import datetime
-from django.db.models import Max
-from django.db.models.functions import Length
+from django.db.models import Count, Max
+from django.db.models.functions import ExtractWeek, ExtractYear, Length
from django.http import Http404
from django.shortcuts import get_object_or_404, render
-from .models import Timetable, Group, Course, Year
+from .models import Course, Group, Room, Timetable, Year
from .utils import get_current_week, get_current_or_next_week, get_week, group_courses
import edt
@@ -97,7 +97,36 @@ def calendars(request, year_slug, timetable_slug, group_slug):
return render(request, "calendars.html", {"group": group, "groups": groups})
def rooms(request):
- return render(request, "index.html")
+ # On récupère les dates allant de cette semaine à dans un mois
+ start, _ = get_week(*get_current_week())
+ end = start + datetime.timedelta(weeks=4)
+
+ # Récupération des salles et de toutes les semaines où elles sont
+ # concernées
+ # Cette requête est un peu lente sur sqlite… j’espère que ce sera mieux
+ # sur la base de prod.
+ rooms = Room.objects.filter(course__begin__gte=start, course__begin__lt=end) \
+ .annotate(year=ExtractYear("course__begin"),
+ week=ExtractWeek("course__begin")) \
+ .order_by("name").annotate(c=Count("*"))
+
+ rooms_weeks = []
+ for room in rooms:
+ if len(rooms_weeks) == 0 or rooms_weeks[-1].id != room.id:
+ room.weeks = []
+ rooms_weeks.append(room)
+
+ date, _ = get_week(room.year, room.week)
+ rooms_weeks[-1].weeks.append(date)
+
+ return render(request, "group_list.html", {"groups": rooms_weeks})
+
+def room_timetable(request, room_slug):
+ room = get_object_or_404(Room, slug=room_slug)
+ courses = Course.objects.filter(rooms__in=(room,)).order_by("begin")
+
+ return render(request, "timetable.html", {"group": room, "courser": courses,
+ })
def ctx_processor(request):
return {"celcatsanitizer_version": edt.VERSION}