aboutsummaryrefslogtreecommitdiff
path: root/views.py
diff options
context:
space:
mode:
authorAlban Gruin2017-01-20 14:37:49 +0100
committerAlban Gruin2017-01-20 14:37:49 +0100
commita4c9f9027c443a32ff3475dc292c7495f685b651 (patch)
treefa5bb432284ad6964519e05c79e93cad4a45aae3 /views.py
parent5349208724305c9ec1ea4ab1c51af9969dc586e0 (diff)
Affichage des emplois du temps par semaine
Diffstat (limited to 'views.py')
-rw-r--r--views.py28
1 files changed, 24 insertions, 4 deletions
diff --git a/views.py b/views.py
index 07572e9..d11c026 100644
--- a/views.py
+++ b/views.py
@@ -1,19 +1,39 @@
from django.http import HttpResponse
+from django.db.models import Count
from django.shortcuts import get_object_or_404, render, render_to_response
-from django.db.models import Q
+from django.utils import timezone
from edt.models import Timetable, Group, Course
+import datetime
+
+def get_week(year, week):
+ start = timezone.make_aware(datetime.datetime.strptime("{0}-W{1:02d}-1".format(year, week), "%Y-W%W-%w"))
+ end = start + datetime.timedelta(weeks=1)
+
+ return start, end
+
def index(request):
timetables = Timetable.objects.all()
groups = Group.objects.filter(tp__isnull=False).order_by("name")
+ for group in groups:
+ courses = Course.objects.get_courses_for_group(group).values("begin").annotate(count=Count("begin"))
+ weeks = []
+ for course in courses:
+ year, week, _ = course["begin"].isocalendar()
+ date, _ = get_week(year, week)
+ if date not in weeks:
+ weeks.append(date)
+ group.weeks = weeks
+
return render_to_response("index.html", {"timetables": timetables, "groups": groups})
-def timetable(request, timetable_slug, group_slug):
+def timetable(request, timetable_slug, year, week, group_slug):
+ start, end = get_week(int(year), int(week))
+
timetable = get_object_or_404(Timetable, slug=timetable_slug)
group = get_object_or_404(Group, slug=group_slug, timetable=timetable)
-
- courses = Course.objects.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).order_by("begin").distinct()
+ courses = Course.objects.get_courses_for_group(group, begin__gte=start, begin__lt=end)
return render_to_response("timetable.html", {"timetable": timetable, "group": group, "courses": courses})