1
0
mirror of https://gitlab.crans.org/bde/nk20 synced 2024-11-27 02:43:01 +00: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
No known key found for this signature in database
GPG Key ID: 6C79278F3FCDCC02
2 changed files with 67 additions and 36 deletions

View File

@ -3,7 +3,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-07-17 13:48+0200\n" "POT-Creation-Date: 2019-07-24 22:37+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -17,105 +17,125 @@ msgstr ""
msgid "source" msgid "source"
msgstr "source" msgstr "source"
#: admin.py:120 admin.py:138 models/transactions.py:25 #: admin.py:120 admin.py:148 models/transactions.py:25
#: models/transactions.py:52 #: models/transactions.py:52
msgid "destination" msgid "destination"
msgstr "destination" msgstr "destination"
#: apps.py:11 models/notes.py:45 #: apps.py:15 models/notes.py:47
msgid "note" msgid "note"
msgstr "note" msgstr "note"
#: models/notes.py:22 #: models/notes.py:24
msgid "account balance" msgid "account balance"
msgstr "solde du compte" msgstr "solde du compte"
#: models/notes.py:23 #: models/notes.py:25
msgid "in centimes, money credited for this instance" msgid "in centimes, money credited for this instance"
msgstr "en centimes, argent crédité pour cette instance" msgstr "en centimes, argent crédité pour cette instance"
#: models/notes.py:27 #: models/notes.py:29
msgid "active" msgid "active"
msgstr "actif" msgstr "actif"
#: models/notes.py:30 #: models/notes.py:32
msgid "" msgid ""
"Designates whether this note should be treated as active. Unselect this " "Designates whether this note should be treated as active. Unselect this "
"instead of deleting notes." "instead of deleting notes."
msgstr "" msgstr ""
"Indique si la note est active. Désactiver cela plutôt que supprimer la note." "Indique si la note est active. Désactiver cela plutôt que supprimer la note."
#: models/notes.py:35 #: models/notes.py:37
msgid "display image" msgid "display image"
msgstr "image affichée" msgstr "image affichée"
#: models/notes.py:40 models/transactions.py:55 #: models/notes.py:42 models/transactions.py:55
msgid "created at" msgid "created at"
msgstr "créée le" msgstr "créée le"
#: models/notes.py:46 #: models/notes.py:48
msgid "notes" msgid "notes"
msgstr "notes" msgstr "notes"
#: models/notes.py:57 #: models/notes.py:56
msgid "Note"
msgstr "Note"
#: models/notes.py:66 models/notes.py:88
msgid "This alias is already taken."
msgstr "Cet alias est déjà pris."
#: models/notes.py:103
msgid "user" msgid "user"
msgstr "utilisateur" msgstr "utilisateur"
#: models/notes.py:61 #: models/notes.py:107
msgid "one's note" msgid "one's note"
msgstr "note d'un utilisateur" msgstr "note d'un utilisateur"
#: models/notes.py:62 #: models/notes.py:108
msgid "users note" msgid "users note"
msgstr "notes des utilisateurs" msgstr "notes des utilisateurs"
#: models/notes.py:65 #: models/notes.py:114
#, python-format #, python-format
msgid "%(user)s's note" msgid "%(user)s's note"
msgstr "Note de %(user)s" msgstr "Note de %(user)s"
#: models/notes.py:76 #: models/notes.py:125
msgid "club" msgid "club"
msgstr "club" msgstr "club"
#: models/notes.py:80 #: models/notes.py:129
msgid "club note" msgid "club note"
msgstr "note d'un club" msgstr "note d'un club"
#: models/notes.py:81 #: models/notes.py:130
msgid "clubs notes" msgid "clubs notes"
msgstr "notes des clubs" msgstr "notes des clubs"
#: models/notes.py:84 #: models/notes.py:136
#, python-format #, python-format
msgid "Note for %(club)s club" msgid "Note for %(club)s club"
msgstr "Note du club %(club)s" msgstr "Note du club %(club)s"
#: models/notes.py:97 models/transactions.py:32 models/transactions.py:65 #: models/notes.py:149 models/transactions.py:32 models/transactions.py:66
msgid "type" msgid "type"
msgstr "type" msgstr "type"
#: models/notes.py:103 #: models/notes.py:155
msgid "special note" msgid "special note"
msgstr "note spéciale" msgstr "note spéciale"
#: models/notes.py:104 #: models/notes.py:156
msgid "special notes" msgid "special notes"
msgstr "notes spéciales" msgstr "notes spéciales"
#: models/notes.py:115 models/transactions.py:18 #: models/notes.py:167 models/transactions.py:18
msgid "name" msgid "name"
msgstr "nom" msgstr "nom"
#: models/notes.py:125 #: models/notes.py:173
msgid "Invalid alias"
msgstr "Alias invalide"
#: models/notes.py:189
msgid "alias" msgid "alias"
msgstr "alias" msgstr "alias"
#: models/notes.py:126 #: models/notes.py:190
msgid "aliases" msgid "aliases"
msgstr "alias" msgstr "alias"
#: models/transactions.py:28 models/transactions.py:62 #: models/notes.py:218
msgid "Alias too long."
msgstr "L'alias est trop long."
#: models/notes.py:221
msgid "An alias with a similar name already exists."
msgstr "Un alias avec un nom similaire existe déjà."
#: models/transactions.py:28 models/transactions.py:63
msgid "amount" msgid "amount"
msgstr "montant" msgstr "montant"
@ -135,27 +155,27 @@ msgstr "modèles de transaction"
msgid "quantity" msgid "quantity"
msgstr "quantité" msgstr "quantité"
#: models/transactions.py:69 #: models/transactions.py:70
msgid "reason" msgid "reason"
msgstr "raison" msgstr "raison"
#: models/transactions.py:73 #: models/transactions.py:74
msgid "valid" msgid "valid"
msgstr "valide" msgstr "valide"
#: models/transactions.py:77 #: models/transactions.py:79
msgid "transaction" msgid "transaction"
msgstr "transaction" msgstr "transaction"
#: models/transactions.py:78 #: models/transactions.py:80
msgid "transactions" msgid "transactions"
msgstr "transactions" msgstr "transactions"
#: models/transactions.py:89 #: models/transactions.py:116
msgid "membership transaction" msgid "membership transaction"
msgstr "transaction d'adhésion" msgstr "transaction d'adhésion"
#: models/transactions.py:90 #: models/transactions.py:117
msgid "membership transactions" msgid "membership transactions"
msgstr "transactions d'adhésion" msgstr "transactions d'adhésion"

View File

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