From a2fcd4c7c42b6c02ff8ff7dac4aa23b3d17407de Mon Sep 17 00:00:00 2001 From: Alban Gruin Date: Wed, 17 Jan 2018 12:34:11 +0100 Subject: Base du formulaire de QSJPS --- forms.py | 21 +++++++++++++++++++++ templates/form_qsjps.html | 10 ++++++++++ urls.py | 3 ++- views.py | 20 +++++++++++++++++++- 4 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 forms.py create mode 100644 templates/form_qsjps.html diff --git a/forms.py b/forms.py new file mode 100644 index 0000000..34081c0 --- /dev/null +++ b/forms.py @@ -0,0 +1,21 @@ +# Copyright (C) 2018 Alban Gruin +# +# celcatsanitizer is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# celcatsanitizer is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with celcatsanitizer. If not, see . + +from django import forms + + +class QSJPSForm(forms.Form): + begin = forms.DateTimeField(label="Début") + end = forms.DateTimeField(label="Fin") diff --git a/templates/form_qsjps.html b/templates/form_qsjps.html new file mode 100644 index 0000000..2d97a89 --- /dev/null +++ b/templates/form_qsjps.html @@ -0,0 +1,10 @@ +{% extends "index.html" %} + +{% block title %}QSJPS – {% endblock %} + +{% block body %} +
+ {{ form }} + +
+{% endblock %} diff --git a/urls.py b/urls.py index 22011c4..f24bbba 100644 --- a/urls.py +++ b/urls.py @@ -1,4 +1,4 @@ -# Copyright (C) 2017 Alban Gruin +# Copyright (C) 2017-2018 Alban Gruin # # celcatsanitizer is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published @@ -20,6 +20,7 @@ urlpatterns = [ url(r"^$", views.index, name="index"), url(r"^pages/", include("django.contrib.flatpages.urls")), url(r"^salles/$", views.rooms, name="rooms"), + url(r"^salles/qsjps$", views.qsjps, name="qsjps"), url(r"^salles/(?P[-\w]+)/$", views.room_timetable, name="room-timetable"), url(r"^salles/(?P[-\w]+)/(?P[0-9]{4})/(?P[0-4]?[0-9]|5[0-3])$", views.room_timetable, name="room-timetable"), url(r"^(?P[-\w]+)/$", views.mention_list, name="mentions"), diff --git a/views.py b/views.py index 97a1d28..e8fc259 100644 --- a/views.py +++ b/views.py @@ -1,4 +1,4 @@ -# Copyright (C) 2017 Alban Gruin +# Copyright (C) 2017-2018 Alban Gruin # # celcatsanitizer is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published @@ -19,7 +19,9 @@ 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.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 @@ -144,5 +146,21 @@ 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": + # Si on traite un formulaire, on le valide + form = QSJPSForm(request.POST) + if form.is_valid(): + # Formulaire validé + return None + else: + # Formulaire invalide, on le raffiche avec une erreur + return render(request, "form_qsjps.html", {"form": form}) + else: + # Sinon, affichage d’un formulaire vide + form = QSJPSForm() + return render(request, "form_qsjps.html", {"form": form}) + def ctx_processor(request): return {"celcatsanitizer_version": edt.VERSION} -- cgit v1.2.1