diff options
author | Alban Gruin | 2017-02-09 11:38:29 +0100 |
---|---|---|
committer | Alban Gruin | 2017-02-09 11:38:29 +0100 |
commit | ef3d37c4be68e9055e099e955cbdc7934a6d0b65 (patch) | |
tree | b0e4a8a5e72e5108e7b54df31fef2fef0e5b3857 /models.py | |
parent | 65eb38093246b6483a427639462d4e55abf7621c (diff) |
Déduplication du nom de cours dans la base de données
Diffstat (limited to 'models.py')
-rw-r--r-- | models.py | 18 |
1 files changed, 11 insertions, 7 deletions
@@ -60,9 +60,9 @@ class Group(models.Model): 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) def __str__(self): - return "{0} - {1}".format(self.timetable.name, self.name) + return self.name - def save(self): + def save(self, *args, **kwargs): try: parts = self.celcat_name.split("-")[-2:] group = parts[1].strip()[2:] @@ -101,10 +101,10 @@ class Subscription(models.Model): def __str__(self): return "{0} - {1}".format(self.email, self.group) - def save(self): + def save(self, *args, **kwargs): if self.token == "": self.token = hashlib.sha1(os.urandom(128)).hexdigest() - super(Subscription, self).save() + super(Subscription, self).save(*args, **kwargs) class Meta: @@ -160,9 +160,13 @@ class Course(models.Model): def __str__(self): return self.name - def save(self): - self.type_.replace("COURS", "Cours") - super(Course, self).save() + def save(self, *args, **kwargs): + if self.type is not None: + self.type = self.type.replace("COURS", "cours") + if self.name is not None: + self.name = self.name.split("(")[0].strip() + + super(Course, self).save(*args, **kwargs) class Meta: |