8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-09-28 07:03:09 +00:00

define function that adds error to messages, to use with protectederror

This commit is contained in:
Kagamino 2018-05-29 20:34:45 +02:00
parent acb41cf375
commit 40c60405d4
No known key found for this signature in database
GPG key ID: 627AC4A983DA11E3

View file

@ -39,6 +39,7 @@ from __future__ import unicode_literals
from django.utils import timezone
from django.db.models import Q
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.utils.translation import ugettext as _
from cotisations.models import Cotisation, Facture, Vente
from machines.models import Interface, Machine
@ -377,3 +378,17 @@ def get_input_formats_help_text(input_formats):
)
)
return help_text
def messages_protected_error(messages, request, item, error):
"""Add an error message, specific to ProtectedError exception."""
messages.error(
request,
_("[%(item_class_name)s] %(item_name)s can't be deleted \
because it is used by [%(foreign_class_name)s] %(foreign_name)s.", % {
'item_class_name': item.__class__.__name__,
'item_name': item.name,
'foreign_class_name': error.protected_objects[0].__class__.__name__,
'foreign_name': error.protected_objects[0].name,
})
)