aboutsummaryrefslogtreecommitdiff
path: root/views.py
diff options
context:
space:
mode:
authorAlban Gruin2017-09-07 23:12:57 +0200
committerAlban Gruin2017-09-07 23:12:57 +0200
commit5767fe2b49858dd8174193ffa8c2e8b3fda1fc6c (patch)
tree5176298f82739e146621f8661bdf4a01f9062b0e /views.py
parentdaa35602eeee6b15cea2b4e92a0556de2a1b4905 (diff)
Utilisation du modèle Year où nécessaire
Diffstat (limited to 'views.py')
-rw-r--r--views.py17
1 files changed, 10 insertions, 7 deletions
diff --git a/views.py b/views.py
index 141dde8..ea3a5be 100644
--- a/views.py
+++ b/views.py
@@ -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: