aboutsummaryrefslogtreecommitdiff
path: root/views.py
diff options
context:
space:
mode:
Diffstat (limited to 'views.py')
-rw-r--r--views.py41
1 files changed, 27 insertions, 14 deletions
diff --git a/views.py b/views.py
index bd93712..c0c63cb 100644
--- a/views.py
+++ b/views.py
@@ -15,14 +15,16 @@
import datetime
-from django.conf import settings
from django.db.models import Max
+from django.db.models.functions import Length
from django.http import Http404
from django.shortcuts import get_object_or_404, render
from .models import Timetable, Group, Course, Year
from .utils import get_current_week, get_current_or_next_week, get_week, group_courses
+import edt
+
def index(request):
years = Year.objects.order_by("name")
return render(request, "index.html", {"elements": years})
@@ -39,13 +41,12 @@ def group_list_common(request, timetable, groups):
groups_weeks = Course.objects.get_weeks(begin__gte=start, begin__lt=end, timetable=timetable) \
.values("groups__mention", "groups__subgroup",
- "groups__td", "groups__tp", "year", "week")
+ "year", "week")
for group in groups:
for group_week in groups_weeks:
if group.corresponds_to(timetable.id, group_week["groups__mention"],
- group_week["groups__subgroup"], group_week["groups__td"],
- group_week["groups__tp"]):
+ group_week["groups__subgroup"]):
if not hasattr(group, "weeks"):
group.weeks = []
@@ -60,15 +61,16 @@ def group_list_common(request, timetable, groups):
def group_list(request, year_slug, timetable_slug):
timetable = get_object_or_404(Timetable, year__slug=year_slug, slug=timetable_slug)
- groups = Group.objects.get_relevant_groups(timetable=timetable).order_by("name")
+ groups = Group.objects.get_relevant_groups(timetable)
return group_list_common(request, timetable, groups)
def timetable(request, year_slug, timetable_slug, group_slug, year=None, week=None):
current_year, current_week = get_current_or_next_week()
- is_old_timetable = False
+ is_old_timetable, provided_week = False, True
if year is None or week is None:
year, week = current_year, current_week
+ provided_week = False
elif (int(year), int(week)) < (current_year, current_week):
is_old_timetable = True
@@ -77,20 +79,31 @@ 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)
- if group.children.count():
- return group_list_common(request, timetable, Group.objects.get_relevant_children(group))
+ if Group.objects.filter(timetable=timetable, mention=group.mention,
+ subgroup__startswith=group.subgroup).count() > 1:
+ subgroups = Group.objects.get_relevant_groups(timetable, mention=group.mention,
+ subgroup__startswith=group.subgroup)
+ return group_list_common(request, timetable, subgroups)
- courses = Course.objects.get_courses_for_group(group, begin__gte=start, begin__lt=end) \
- .annotate(Max("last_update"))
- if courses.count() == 0:
+ courses = Course.objects.get_courses_for_group(group, begin__gte=start, begin__lt=end)
+ if courses.count() == 0 and provided_week:
raise Http404
+ last_update = courses.aggregate(Max("last_update"))["last_update__max"]
grouped_courses = group_courses(courses)
return render(request, "timetable.html", {"group": group, "courses": grouped_courses,
- "last_update": courses.first().last_update__max,
+ "last_update": last_update,
"year": year, "week": int(week),
"is_old_timetable": is_old_timetable})
-def contact(request):
- return render(request, "contact.html", {"email": settings.ADMINS[0][1]})
+def calendars(request, year_slug, timetable_slug, group_slug):
+ group = get_object_or_404(Group, timetable__year__slug=year_slug,
+ timetable__slug=timetable_slug, slug=group_slug)
+ groups = Group.objects.get_parents(group).annotate(length=Length("subgroup")) \
+ .order_by("length")
+
+ return render(request, "calendars.html", {"group": group, "groups": groups})
+
+def ctx_processor(request):
+ return {"celcatsanitizer_version": edt.VERSION}