aboutsummaryrefslogtreecommitdiff
path: root/views.py
blob: 07572e97e22e19b905ba9be59325a939f9e8397c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
from django.http import HttpResponse
from django.shortcuts import get_object_or_404, render, render_to_response
from django.db.models import Q

from edt.models import Timetable, Group, Course

def index(request):
    timetables = Timetable.objects.all()
    groups = Group.objects.filter(tp__isnull=False).order_by("name")

    return render_to_response("index.html", {"timetables": timetables, "groups": groups})

def timetable(request, timetable_slug, group_slug):
    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()

    return render_to_response("timetable.html", {"timetable": timetable, "group": group, "courses": courses})