diff options
author | Alban Gruin | 2017-02-28 13:30:03 +0100 |
---|---|---|
committer | Alban Gruin | 2017-02-28 13:30:03 +0100 |
commit | ce0ed9347adde9ca80c11efe79766c966d5749ba (patch) | |
tree | e371a2d06374efbad1c1c8a4558d92ee0a07c025 /utils.py | |
parent | a543aaa14957f390d2b640a264113b639c7d3194 (diff) | |
parent | 66be6f2e7a3c642fb3c69e7c2a70cc3f898d77ea (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.py | 27 |
1 files changed, 27 insertions, 0 deletions
@@ -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] |