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:
@ -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):
|
||||
"""
|
||||
|
Reference in New Issue
Block a user