diff options
Diffstat (limited to 'views.py')
-rw-r--r-- | views.py | 12 |
1 files changed, 8 insertions, 4 deletions
@@ -14,9 +14,11 @@ # along with celcatsanitizer. If not, see <http://www.gnu.org/licenses/>. from django.conf import settings +from django.db.models import Max +from django.http import Http404 from django.shortcuts import get_object_or_404, render -from .models import Timetable, LastUpdate, Group, Course, Year +from .models import Timetable, Group, Course, Year from .utils import get_current_week, get_week, group_courses def index(request): @@ -60,12 +62,14 @@ def timetable(request, year_slug, timetable_slug, group_slug, year=None, week=No timetable = get_object_or_404(Timetable, year__slug=year_slug, slug=timetable_slug) group = get_object_or_404(Group, slug=group_slug, timetable=timetable) - last_update = get_object_or_404(LastUpdate, timetable=timetable, week=week, year=year) - courses = Course.objects.get_courses_for_group(group, begin__gte=start, begin__lt=end) + + courses = Course.objects.get_courses_for_group(group, begin__gte=start, begin__lt=end).annotate(Max("last_update")) + if courses.count == 0: + raise Http404 grouped_courses = group_courses(courses) - return render(request, "timetable.html", {"group": group, "courses": grouped_courses, "last_update": last_update.date, "year": year, "week": int(week)}) + return render(request, "timetable.html", {"group": group, "courses": grouped_courses, "last_update": courses.first().last_update__max, "year": year, "week": int(week)}) def contact(request): return render(request, "contact.html", {"email": settings.ADMINS[0][1]}) |