def clean(self): cleaned_data = super(FormWithTitle, self).clean() title = cleaned_data.get('title') if title is None or not title.strip(): title = 'Titre par défaut' cleaned_data['title'] = title try: slugify_raise_on_invalid(title) except InvalidSlugError as e: self._errors['title'] = self.error_class( [_("Ce titre n'est pas autorisé, son slug est invalide {} !").format(e)]) return cleaned_data
def clean(self): cleaned_data = super(FormWithTitle, self).clean() title = cleaned_data.get('title') if title is not None and not title.strip(): self._errors['title'] = self.error_class( [_(u'Le champ du titre ne peut être vide.')]) if 'title' in cleaned_data: del cleaned_data['title'] try: slugify_raise_on_invalid(title) except InvalidSlugError as e: self._errors['title'] = self.error_class( [_(u"Ce titre n'est pas autorisé, son slug est invalide {} !").format(e if e.message else '')]) return cleaned_data