aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--models.py4
-rw-r--r--utils.py37
2 files changed, 22 insertions, 19 deletions
diff --git a/models.py b/models.py
index 478b48f..32a5903 100644
--- a/models.py
+++ b/models.py
@@ -66,14 +66,14 @@ class Group(models.Model):
timetable = models.ForeignKey(Timetable, on_delete=models.CASCADE, verbose_name="emploi du temps")
mention = models.CharField(max_length=32)
- subgroup = models.CharField(max_length=1, verbose_name="sous-groupe")
+ subgroup = models.CharField(max_length=1, verbose_name="sous-groupe", null=True)
td = models.IntegerField(verbose_name="groupe de TD", null=True)
tp = models.IntegerField(verbose_name="groupe de TP", null=True)
slug = models.SlugField(max_length=64, default="")
def corresponds_to(self, timetable_id, mention, subgroup, td, tp):
- return self.timetable.id == timetable_id and self.mention == mention and self.subgroup == subgroup and (self.td == td or self.td is None or td is None) and (self.tp == tp or self.tp is None or tp is None)
+ return self.timetable.id == timetable_id and self.mention.startswith(mention) and (self.subgroup == subgroup or self.subgroup is None) and (self.td == td or self.td is None or td is None) and (self.tp == tp or self.tp is None or tp is None)
@property
def group_info(self):
diff --git a/utils.py b/utils.py
index cff4c9c..8e87c0f 100644
--- a/utils.py
+++ b/utils.py
@@ -49,25 +49,28 @@ def group_courses(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)))$")
+ # ^([\w ]+?)(\s*\-\s*(((CM)(\w))|((TD)(\w)(\d))|((TP)(\w)(\d)(\d))))?$
+ # ^ début de la ligne
+ # ([\w ]+?) 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
+ # )? groupe optionel
+ # $ fin de la ligne
+ group_regex = re.compile("^([\w ]+?)(\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]
+ if parts[1] == 0:
+ return parts[0], None, None, None
+ elif parts[4] == "CM":
+ return parts[0], parts[5], None, None
+ elif parts[7] == "TD":
+ return parts[0], parts[8], parts[9], None
+ elif parts[11] == "TP":
+ return parts[0], parts[12], parts[13], parts[14]