diff options
Diffstat (limited to 'views.py')
-rw-r--r-- | views.py | 17 |
1 files changed, 10 insertions, 7 deletions
@@ -21,24 +21,27 @@ from django.template import Context, loader from django.db.models import Count from .forms import SubscribeForm -from .models import Timetable, LastUpdate, Group, Subscription, Course +from .models import Timetable, LastUpdate, Group, Subscription, Course, Year from .utils import get_current_week, get_week, group_courses def index(request): - years = Timetable.objects.order_by("year").values("year").annotate(count=Count("year")) + years = Year.objects.order_by("name") return render(request, "index.html", {"years": years}) -def mention_list(request, year): +def mention_list(request, year_slug): + year = get_object_or_404(Year, slug=year_slug) timetables = Timetable.objects.order_by("name").filter(year=year) + return render(request, "mention_list.html", {"year": year, "timetables": timetables}) -def group_list(request, year, timetable_slug): +def group_list(request, year_slug, timetable_slug): + get_object_or_404(Year, slug=year_slug) timetable = get_object_or_404(Timetable, slug=timetable_slug) - groups = Group.objects.get_relevant_groups(timetable=timetable).order_by("name") + groups = Group.objects.get_relevant_groups().order_by("name") year, week = get_current_week() start, _ = get_week(year, week) - groups_weeks = Course.objects.get_weeks(begin__gte=start).values("groups__timetable", "groups__mention", "groups__subgroup", "groups__td", "groups__tp", "year", "week") + groups_weeks = Course.objects.get_weeks(begin__gte=start).values("group__timetable", "groups__mention", "groups__subgroup", "groups__td", "groups__tp", "year", "week") for group in groups: for group_week in groups_weeks: @@ -53,7 +56,7 @@ def group_list(request, year, timetable_slug): if hasattr(group, "weeks"): group.weeks.sort() - return render(request, "group_list.html", {"timetables": timetables, "groups": groups}) + return render(request, "group_list.html", {"timetable": timetable, "groups": groups}) def timetable(request, timetable_slug, group_slug, year=None, week=None): if year is None or week is None: |