aboutsummaryrefslogtreecommitdiff
path: root/views.py
diff options
context:
space:
mode:
authorAlban Gruin2017-11-26 18:27:55 +0100
committerAlban Gruin2017-11-26 18:27:55 +0100
commit772caa72ce7f80bfeb5fbb1d05b57838dafd48c3 (patch)
tree00482ecc09db0eefd0617c6f9225b7c3e6f96161 /views.py
parentffffd9842dbaba0b0e89ff5f434f45792e2b73b6 (diff)
parent4998865c2d5e94c53547e44aed1dc825163c0c4a (diff)
Merge branch 'stable/0.12.z' into prod/pa1ch/0.y.zv0.12.0-pa1ch
Diffstat (limited to 'views.py')
-rw-r--r--views.py29
1 files changed, 10 insertions, 19 deletions
diff --git a/views.py b/views.py
index c0c63cb..c647fac 100644
--- a/views.py
+++ b/views.py
@@ -31,21 +31,23 @@ def index(request):
def mention_list(request, year_slug):
year = get_object_or_404(Year, slug=year_slug)
- timetables = Timetable.objects.order_by("name").filter(year=year)
+ timetables = Timetable.objects.order_by("name").filter(year=year).select_related("year")
return render(request, "index.html", {"year": year, "elements": timetables})
-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.filter(timetable=timetable, hidden=False).order_by("name")
+
start, _ = get_week(*get_current_week())
end = start + datetime.timedelta(weeks=4)
- groups_weeks = Course.objects.get_weeks(begin__gte=start, begin__lt=end, timetable=timetable) \
- .values("groups__mention", "groups__subgroup",
- "year", "week")
+ groups_weeks = Course.objects.get_weeks(begin__gte=start, begin__lt=end, groups__in=groups)
for group in groups:
for group_week in groups_weeks:
- if group.corresponds_to(timetable.id, group_week["groups__mention"],
+ if group.corresponds_to(group_week["groups__mention"],
+ group_week["groups__semester"],
group_week["groups__subgroup"]):
if not hasattr(group, "weeks"):
group.weeks = []
@@ -59,11 +61,6 @@ def group_list_common(request, timetable, groups):
return render(request, "group_list.html", {"timetable": timetable, "groups": 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)
- 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, provided_week = False, True
@@ -74,19 +71,13 @@ def timetable(request, year_slug, timetable_slug, group_slug, year=None, week=No
elif (int(year), int(week)) < (current_year, current_week):
is_old_timetable = True
- start, end = get_week(int(year), int(week))
+ start, end = get_week(year, week)
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.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)
- if courses.count() == 0 and provided_week:
+ if not courses.exists() and provided_week:
raise Http404
last_update = courses.aggregate(Max("last_update"))["last_update__max"]