1
0
mirror of https://gitlab.crans.org/bde/nk20 synced 2025-06-29 20:51:11 +02:00

Implement clean methode for Note

This commit is contained in:
Alexandre Iooss
2019-07-24 22:40:31 +02:00
parent 32a37eae29
commit fb8e6cafef
2 changed files with 67 additions and 36 deletions

View File

@ -51,7 +51,7 @@ class Note(PolymorphicModel):
"""
:return: Pretty name of this note
"""
return 'Not implemented'
return str(self)
pretty.short_description = _('Note')
@ -63,7 +63,7 @@ class Note(PolymorphicModel):
if aliases.exists():
# Alias exists, so check if it is linked to this note
if aliases.first().note != self:
raise ValidationError
raise ValidationError(_('This alias is already taken.'))
# Save note
super().save(*args, **kwargs)
@ -77,6 +77,20 @@ class Note(PolymorphicModel):
a.note = self
a.save(force_insert=True)
def clean(self, *args, **kwargs):
"""
Verify alias (simulate save)
"""
aliases = Alias.objects.filter(name=str(self))
if aliases.exists():
# Alias exists, so check if it is linked to this note
if aliases.first().note != self:
raise ValidationError(_('This alias is already taken.'))
else:
# Alias does not exist yet, so check if it can exist
a = Alias(name=str(self))
a.clean()
class NoteUser(Note):
"""
@ -144,9 +158,6 @@ class NoteSpecial(Note):
def __str__(self):
return self.special_type
def pretty(self):
return self.special_type
class Alias(models.Model):
"""