aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--models.py5
-rw-r--r--tests.py14
-rw-r--r--utils.py12
3 files changed, 20 insertions, 11 deletions
diff --git a/models.py b/models.py
index abb00bf..fb0e757 100644
--- a/models.py
+++ b/models.py
@@ -101,7 +101,7 @@ class Group(models.Model):
hidden = models.BooleanField(verbose_name="caché", default=False)
- def corresponds_to(self, mention, subgroup):
+ def corresponds_to(self, mention, semester, subgroup):
subgroup_corresponds = True
if self.subgroup is not None and subgroup is not None:
subgroup_corresponds = self.subgroup.startswith(subgroup)
@@ -109,11 +109,12 @@ class Group(models.Model):
# TODO adapter pour semester
return (self.mention.startswith(mention) or \
mention.startswith(self.mention)) and \
+ (self.semester == semester or semester is None) and \
subgroup_corresponds
@property
def group_info(self):
- return self.mention, self.subgroup
+ return self.mention, self.semester, self.subgroup
def __str__(self):
return self.name
diff --git a/tests.py b/tests.py
index 77fa120..1425a84 100644
--- a/tests.py
+++ b/tests.py
@@ -152,12 +152,12 @@ class GroupTestCase(TestCase):
general = Group.objects.get(celcat_name="L1 info (toutes sections et semestres confondus)", timetable=self.timetable)
- self.assertEqual(cma.group_info, ("L1 info s2 ", "A"))
- self.assertEqual(tda2.group_info, ("L1 info s2 ", "A2"))
- self.assertEqual(tpa21.group_info, ("L1 info s2 ", "A21"))
+ self.assertEqual(cma.group_info, ("L1 info", 2, "A"))
+ self.assertEqual(tda2.group_info, ("L1 info", 2, "A2"))
+ self.assertEqual(tpa21.group_info, ("L1 info", 2, "A21"))
- self.assertEqual(cmb.group_info, ("L1 info s2 ", "B"))
- self.assertEqual(tdb2.group_info, ("L1 info s2 ", "B2"))
- self.assertEqual(tpb21.group_info, ("L1 info s2 ", "B21"))
+ self.assertEqual(cmb.group_info, ("L1 info", 2, "B"))
+ self.assertEqual(tdb2.group_info, ("L1 info", 2, "B2"))
+ self.assertEqual(tpb21.group_info, ("L1 info", 2, "B21"))
- self.assertEqual(general.group_info, ("L1 info ", ""))
+ self.assertEqual(general.group_info, ("L1 info", None, ""))
diff --git a/utils.py b/utils.py
index 103969e..9f0a6b5 100644
--- a/utils.py
+++ b/utils.py
@@ -62,10 +62,18 @@ def parse_group(name):
group_regex = re.compile(r"^(.+?)\s*(s(\d)\s+)?((CM|TD|TP|G)(\w\d{0,3}))?(\s+\(.+\))?$")
search = group_regex.search(name)
if search is None:
- return name, None
+ return name, None, None
parts = search.groups()
- return parts[0], int(parts[2]), parts[5]
+
+ # On retourne la section (parts[0]), le semestre (parts[2]) et le groupe (parts[5])
+ if parts[2] is not None:
+ return parts[0], int(parts[2]), parts[5]
+ else:
+ # Si jamais le semestre n’est pas présent dans la chaine parsée,
+ # parts[2] sera à None et sa conversion vers un int va provoquer
+ # une erreur.
+ return parts[0], None, parts[5]
def tz_now():
"""Retourne la date et l’heure avec le bon fuseau horaire"""