aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--forms.py2
-rw-r--r--management/parsers/ups2018.py26
-rw-r--r--views.py5
3 files changed, 23 insertions, 10 deletions
diff --git a/forms.py b/forms.py
index d4ee94d..b1a3052 100644
--- a/forms.py
+++ b/forms.py
@@ -64,6 +64,6 @@ class QSJPSForm(forms.Form):
form_data["begin"] >= form_data["end"]:
# Si l’heure de fin est plus petite ou égale, on affiche
# une erreur.
- self.add_error("end", "L’heure de début doit être"
+ self.add_error("end", "L’heure de début doit être "
"supérieure à celle de fin.")
return form_data
diff --git a/management/parsers/ups2018.py b/management/parsers/ups2018.py
index 15c629a..522a26a 100644
--- a/management/parsers/ups2018.py
+++ b/management/parsers/ups2018.py
@@ -14,10 +14,12 @@
# along with celcatsanitizer. If not, see <http://www.gnu.org/licenses/>.
from datetime import datetime, timedelta
+from collections import OrderedDict
import asyncio
import calendar
import json
+import re
from django.utils import timezone
@@ -85,16 +87,20 @@ class Parser(AbstractParser):
if event_year != year or event_week != week:
return
- course = Course.objects.create(
- source=self.source, begin=begin, end=end
- )
-
data = event["text"].split("<br>")
rooms = None
if data[0] == "Global Event":
return
- i = 0
+ course = Course.objects.create(
+ source=self.source, begin=begin, end=end
+ )
+
+ min_i = 0
+ if len(data) > 0 and re.match("^\(\d+:\d+-\d+:\d+\)$", data[0]):
+ min_i = 1
+
+ i = min_i
while i < len(data) and not data[i].startswith(
("L1 ", "L2 ", "L3 ", "L3P ", "M1 ", "M2 ", "DEUST ", "MAG1 ",
"1ERE ANNEE ", "2EME ANNEE ", "3EME ANNEE ",
@@ -103,11 +109,15 @@ class Parser(AbstractParser):
i += 1
groups = data[i]
- if i - 1 >= 0:
- course.name = ", ".join(set(data[i - 1].split(';')))
+ if i - 1 >= min_i:
+ # TODO: le jour où la version minimale supportée sera
+ # Python 3.7, il sera possible de remplacer OrderedDict
+ # par un dictionnaire classique.
+ names = OrderedDict.fromkeys(data[i - 1].split(';'))
+ course.name = ", ".join(names.keys())
else:
course.name = "Sans nom"
- if i - 2 >= 0:
+ if i - 2 >= min_i:
course.type = data[i - 2]
if len(data) >= i + 2:
rooms = data[i + 1]
diff --git a/views.py b/views.py
index e45ece3..de38f35 100644
--- a/views.py
+++ b/views.py
@@ -259,6 +259,8 @@ def room_timetable(request, room_slug, year=None, week=None):
@csrf_exempt
def qsjps(request):
+ status = 200
+
if request.method == "POST":
# Si on traite un formulaire, on le valide
form = QSJPSForm(request.POST)
@@ -278,12 +280,13 @@ def qsjps(request):
# Si le formulaire est invalide, on ré-affiche le formulaire
# avec les erreurs
+ status = 400
else:
# Si le formulaire n’a pas été soumis, on en instancie un
# nouveau
form = QSJPSForm()
- return render(request, "qsjps_form.html", {"form": form})
+ return render(request, "qsjps_form.html", {"form": form}, status=status)
def ctx_processor(request):