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 /models.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 'models.py')
-rw-r--r-- | models.py | 22 |
1 files changed, 5 insertions, 17 deletions
@@ -20,6 +20,8 @@ from django.db.models.expressions import RawSQL from django.db.models.functions import Extract, ExtractYear from django.utils.text import slugify +from .utils import parse_group + import hashlib import os @@ -81,23 +83,9 @@ class Group(models.Model): return self.name def save(self, *args, **kwargs): - try: - parts = self.celcat_name.split("-")[-2:] - group = parts[1].strip()[2:] - - self.mention = parts[0].strip() - self.subgroup = group[0] - - if len(group) > 1: - self.td = int(group[1]) - if len(group) > 2: - self.tp = int(group[2]) - except: - print("Malformed name: {0}. Ignoring".format(self.celcat_name)) - finally: - if self.name == "": - self.name = self.celcat_name - + self.mention, self.subgroup, self.td, self.tp = parse_group(self.celcat_name) + if self.name == "": + self.name = self.celcat_name self.slug = slugify(self.name) super(Group, self).save() |