aboutsummaryrefslogtreecommitdiff
path: root/utils.py
diff options
context:
space:
mode:
authorAlban Gruin2017-02-28 13:30:03 +0100
committerAlban Gruin2017-02-28 13:30:03 +0100
commitce0ed9347adde9ca80c11efe79766c966d5749ba (patch)
treee371a2d06374efbad1c1c8a4558d92ee0a07c025 /utils.py
parenta543aaa14957f390d2b640a264113b639c7d3194 (diff)
parent66be6f2e7a3c642fb3c69e7c2a70cc3f898d77ea (diff)
Merge branch 'stable/0.y.z' into prod/pa1ch/0.y.zv0.7.0-pa1ch
Diffstat (limited to 'utils.py')
-rw-r--r--utils.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/utils.py b/utils.py
index 4ce3a21..cff4c9c 100644
--- a/utils.py
+++ b/utils.py
@@ -17,6 +17,7 @@
from django.utils import timezone
import datetime
+import re
def get_current_week():
return timezone.now().isocalendar()[:2]
@@ -44,3 +45,29 @@ def group_courses(courses):
grouped_courses[-1].append(course)
return grouped_courses
+
+def parse_group(name):
+ # Explication de la regex
+ #
+ # ^(.+?)\s*\-\s*(((CM)(\w))|((TD)(\w)(\d))|((TP)(\w)(\d)(\d)))$
+ # ^ début de la ligne
+ # (.+?) correspond à au moins un caractère
+ # \s* zéro, un ou plusieurs espaces
+ # \- un tiret
+ # \s* zéro, un ou plusieurs espaces
+ # (((CM)(\w))| correspond à CM suivi d'une lettre ou...
+ # ((TD)(\w)(\d))| ... à TD suivi d'une lettre et d'un chiffre ou...
+ # ((TP)(\w)(\d)(\d))) ... à TP suivi d'une lettre et de deux chiffres
+ # $ fin de la ligne
+ group_regex = re.compile("^(.+?)\s*\-\s*(((CM)(\w))|((TD)(\w)(\d))|((TP)(\w)(\d)(\d)))$")
+ search = group_regex.search(name)
+ if search is None:
+ return None, None, None, None
+
+ parts = search.groups(0)
+ if parts[3] == "CM":
+ return parts[0], parts[4], None, None
+ elif parts[6] == "TD":
+ return parts[0], parts[7], parts[8], None
+ elif parts[10] == "TP":
+ return parts[0], parts[11], parts[12], parts[13]