diff options
author | Alban Gruin | 2018-04-21 15:20:01 +0200 |
---|---|---|
committer | Alban Gruin | 2018-04-21 15:21:33 +0200 |
commit | a6d14aa482e322fcd1946ea2541272477b4f8c6b (patch) | |
tree | e8c32f4c75853e6917ea25ab35fdddb99b6a92cf /views.py | |
parent | 7f0fa4871566050e283845ee0577603ded70df0f (diff) |
Ajout d’une liste complète des groupes et d’une liste des semaines
Diffstat (limited to 'views.py')
-rw-r--r-- | views.py | 54 |
1 files changed, 54 insertions, 0 deletions
@@ -79,6 +79,43 @@ def group_list(request, year_slug, timetable_slug): {"timetable": timetable, "groups": groups}) +def groups_all(request, year_slug, timetable_slug): + # Récupération de l’emploi du temps et du groupe + timetable = get_object_or_404(Timetable, year__slug=year_slug, + slug=timetable_slug) + groups = Group.objects.filter(source=timetable.source).order_by("name") + + # Rendu de la page + return render(request, "groups_all_list.html", + {"timetable": timetable, "elements": groups}) + + +def group_weeks(request, year_slug, timetable_slug, group_slug): + # Récupération de l’emploi du temps et des groupes + timetable = get_object_or_404(Timetable, year__slug=year_slug, + slug=timetable_slug) + group = get_object_or_404(Group, slug=group_slug, source=timetable.source) + + # Groupes parents + groups = Group.objects.get_parents(group) + + # Récupération de toutes les semaines avec des cours, sans doublons + courses = Course.objects.filter(groups__in=groups) \ + .order_by("year", "week") \ + .annotate(year=ExtractYear("begin"), + week=ExtractWeek("begin")) \ + .values("year", "week") \ + .annotate(c=Count("*")) + + # Conversion des semaines de cours en dates + weeks = [get_week(course["year"], course["week"])[0] for course in courses] + + # Rendu + return render(request, "group_weeks_list.html", + {"timetable": timetable, "group": group, + "elements": weeks}) + + def timetable_common(request, obj, year=None, week=None, timetable=None): current_year, current_week = get_current_or_next_week() is_old_timetable, provided_week = False, True @@ -198,6 +235,23 @@ def rooms(request): return render(request, "group_list.html", {"groups": rooms_weeks}) +def room_weeks(request, room_slug): + room = get_object_or_404(Room, slug=room_slug) + + # Récupération des semaines de cours + courses = Course.objects.filter(rooms=room) \ + .order_by("year", "week") \ + .annotate(year=ExtractYear("begin"), + week=ExtractWeek("begin")) \ + .values("year", "week") \ + .annotate(c=Count("*")) + + weeks = [get_week(course["year"], course["week"])[0] for course in courses] + + return render(request, "room_weeks_list.html", + {"room": room, "elements": weeks}) + + def room_timetable(request, room_slug, year=None, week=None): room = get_object_or_404(Room, slug=room_slug) return timetable_common(request, room, year, week) |