diff options
author | Alban Gruin | 2017-03-26 14:25:16 +0200 |
---|---|---|
committer | Alban Gruin | 2017-03-26 14:25:16 +0200 |
commit | 10e90edecc88cb45ac7c88c9ec77de00d656d470 (patch) | |
tree | c18e4d5e565f3173f879d2484d3e0ab130264ee1 | |
parent | ce0ed9347adde9ca80c11efe79766c966d5749ba (diff) | |
parent | b0154d43011825731b0e4ff7c4f44b7f5770b3c2 (diff) |
Merge branch 'stable/0.7.z' into prod/pa1ch/0.7.zv0.7.1-pa1ch
-rw-r--r-- | models.py | 4 | ||||
-rw-r--r-- | utils.py | 37 |
2 files changed, 22 insertions, 19 deletions
@@ -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): @@ -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] |