aboutsummaryrefslogtreecommitdiff
path: root/views.py
diff options
context:
space:
mode:
Diffstat (limited to 'views.py')
-rw-r--r--views.py62
1 files changed, 41 insertions, 21 deletions
diff --git a/views.py b/views.py
index e79de47..94de177 100644
--- a/views.py
+++ b/views.py
@@ -24,28 +24,36 @@ from django.views.decorators.csrf import csrf_exempt
from .forms import QSJPSForm
from .models import Course, Group, Room, Timetable, Year
-from .utils import get_current_week, get_current_or_next_week, get_week, group_courses
+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})
+
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, "index.html", {"year": year, "elements": timetables})
+ return render(request, "index.html",
+ {"year": year, "elements": timetables})
+
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(source=timetable.source, hidden=False).order_by("name")
+ timetable = get_object_or_404(Timetable, year__slug=year_slug,
+ slug=timetable_slug)
+ groups = Group.objects.filter(source=timetable.source, 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, groups__in=groups)
+ 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:
@@ -62,7 +70,9 @@ def group_list(request, year_slug, timetable_slug):
if hasattr(group, "weeks"):
group.weeks.sort()
- return render(request, "group_list.html", {"timetable": timetable, "groups": groups})
+ return render(request, "group_list.html",
+ {"timetable": timetable, "groups": groups})
+
def timetable_common(request, obj, year=None, week=None, timetable=None):
current_year, current_week = get_current_or_next_week()
@@ -83,28 +93,34 @@ def timetable_common(request, obj, year=None, week=None, timetable=None):
last_update = courses.aggregate(Max("last_update"))["last_update__max"]
grouped_courses = group_courses(courses)
- return render(request, "timetable.html", {"group": obj, "courses": grouped_courses,
- "last_update": last_update,
- "year": year, "week": int(week),
- "is_old_timetable": is_old_timetable,
- "group_mode": isinstance(obj, Group),
- "timetable": timetable})
+ return render(request, "timetable.html",
+ {"group": obj, "courses": grouped_courses,
+ "last_update": last_update, "year": year, "week": int(week),
+ "is_old_timetable": is_old_timetable,
+ "group_mode": isinstance(obj, Group),
+ "timetable": timetable})
+
-def timetable(request, year_slug, timetable_slug, group_slug, year=None, week=None):
- timetable = get_object_or_404(Timetable, year__slug=year_slug, slug=timetable_slug)
+def timetable(request, year_slug, timetable_slug, group_slug,
+ year=None, week=None):
+ timetable = get_object_or_404(Timetable, year__slug=year_slug,
+ slug=timetable_slug)
group = get_object_or_404(Group, slug=group_slug, source=timetable.source)
return timetable_common(request, group, year, week, timetable)
+
def calendars(request, year_slug, timetable_slug, group_slug):
timetable = get_object_or_404(Timetable, year__slug=year_slug,
slug=timetable_slug)
group = get_object_or_404(Group, source=timetable.source, slug=group_slug)
- groups = Group.objects.get_parents(group).annotate(length=Length("subgroup")) \
- .order_by("length")
+ groups = Group.objects.get_parents(group) \
+ .annotate(length=Length("subgroup")) \
+ .order_by("length")
+
+ return render(request, "calendars.html",
+ {"timetable": timetable, "group": group, "groups": groups})
- return render(request, "calendars.html", {"timetable": timetable,
- "group": group, "groups": groups})
def rooms(request):
# On récupère les dates allant de cette semaine à dans un mois
@@ -117,7 +133,8 @@ def rooms(request):
# cours s’y déroule. Le résultat est trié par le nom de la salle
# et par semaine.
# TODO optimiser cette requête, elle me semble un peu lente
- rooms = Room.objects.filter(course__begin__gte=start, course__begin__lt=end) \
+ rooms = Room.objects.filter(course__begin__gte=start,
+ course__begin__lt=end) \
.order_by("name") \
.annotate(year=ExtractYear("course__begin"),
week=ExtractWeek("course__begin"),
@@ -143,10 +160,12 @@ def rooms(request):
# Rendu de la page.
return render(request, "group_list.html", {"groups": rooms_weeks})
+
def room_timetable(request, room_slug, year=None, week=None):
room = get_object_or_404(Room, slug=room_slug)
return timetable_common(request, room, year, week)
+
@csrf_exempt
def qsjps(request):
if request.method == "POST":
@@ -163,8 +182,8 @@ def qsjps(request):
end = timezone.make_aware(datetime.datetime.combine(day, end_hour))
rooms = Room.objects.qsjps(begin, end)
- return render(request, "qsjps.html", {"rooms": rooms,
- "form": form})
+ return render(request, "qsjps.html",
+ {"rooms": rooms, "form": form})
# Si le formulaire est invalide, on ré-affiche le formulaire
# avec les erreurs
@@ -175,5 +194,6 @@ def qsjps(request):
return render(request, "qsjps_form.html", {"form": form})
+
def ctx_processor(request):
return {"celcatsanitizer_version": edt.VERSION}