aboutsummaryrefslogtreecommitdiff
path: root/views.py
diff options
context:
space:
mode:
Diffstat (limited to 'views.py')
-rw-r--r--views.py49
1 files changed, 38 insertions, 11 deletions
diff --git a/views.py b/views.py
index 2a500c1..bdbbdc2 100644
--- a/views.py
+++ b/views.py
@@ -20,11 +20,13 @@ from django.db.models import Count, Max
from django.db.models.functions import ExtractWeek, ExtractYear, Length
from django.http import Http404
from django.shortcuts import get_object_or_404, render
+from django.utils import timezone
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
@@ -36,11 +38,14 @@ 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)
@@ -66,7 +71,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()
@@ -101,21 +108,26 @@ def timetable_common(request, obj, year=None, week=None, timetable=None):
"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
@@ -146,7 +158,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"),
@@ -172,10 +185,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":
@@ -183,7 +198,18 @@ def qsjps(request):
form = QSJPSForm(request.POST)
if form.is_valid():
# Formulaire validé
- return render(request, "qsjps.html", {"rooms": [], "form": form})
+ day = form.cleaned_data["day"]
+ begin_hour = form.cleaned_data["begin"]
+ end_hour = form.cleaned_data["end"]
+
+ begin = timezone.make_aware(datetime.datetime.combine(day,
+ begin_hour))
+ 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})
+
# Si le formulaire est invalide, on ré-affiche le formulaire
# avec les erreurs
else:
@@ -193,5 +219,6 @@ def qsjps(request):
return render(request, "qsjps_form.html", {"form": form})
+
def ctx_processor(request):
return {"celcatsanitizer_version": edt.VERSION}