diff options
author | Alban Gruin | 2017-01-19 14:55:16 +0100 |
---|---|---|
committer | Alban Gruin | 2017-01-19 14:55:16 +0100 |
commit | eea8dd99b859943d441e36b4958ce7bf61a27e8f (patch) | |
tree | 3e1a70ecfb6d2a6ba6a1a29d5284a0fdae1d7f21 /models.py | |
parent | ffa4f692a6b205de7b677502e1d3f6513bedfa93 (diff) |
Gestion des erreurs
Diffstat (limited to 'models.py')
-rw-r--r-- | models.py | 27 |
1 files changed, 15 insertions, 12 deletions
@@ -28,18 +28,21 @@ class Group(models.Model): return self.name def save(self): - parts = self.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]) - - super(Group, self).save() + try: + parts = self.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.name)) + finally: + super(Group, self).save() class Meta: |