diff options
author | Alban Gruin | 2017-02-27 09:52:08 +0100 |
---|---|---|
committer | Alban Gruin | 2017-02-27 09:52:08 +0100 |
commit | 60092220ca3c47a20f50b677a2bb2173ae3f89a3 (patch) | |
tree | 6d7e8dca6e5e028e598b03e2d98a30f2338a2c9c /utils.py | |
parent | 0649ee9c528d7a3957fb65e195a4a56a702e8d48 (diff) |
Parsage du nom des groupes basé sur une regex pour éviter les problèmes liés à l'ancienne méthode
Diffstat (limited to 'utils.py')
-rw-r--r-- | utils.py | 15 |
1 files changed, 15 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,17 @@ def group_courses(courses): grouped_courses[-1].append(course) return grouped_courses + +def parse_group(name): + 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] |