mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-22 11:23:10 +00:00
uniform and more detailed error messages for protectederror
This commit is contained in:
parent
40c60405d4
commit
f6b48905bf
5 changed files with 52 additions and 141 deletions
|
@ -46,7 +46,7 @@ from users.models import User
|
|||
from re2o.settings import LOGO_PATH
|
||||
from re2o import settings
|
||||
from re2o.views import form
|
||||
from re2o.utils import SortTable, re2o_paginator
|
||||
from re2o.utils import SortTable, re2o_paginator, messages_protected_error
|
||||
from re2o.acl import (
|
||||
can_create,
|
||||
can_edit,
|
||||
|
@ -528,14 +528,8 @@ def del_paiement(request, instances):
|
|||
'method_name': payment_del
|
||||
}
|
||||
)
|
||||
except ProtectedError:
|
||||
messages.error(
|
||||
request,
|
||||
_("The payment method %(method_name)s can't be deleted \
|
||||
because there are invoices using it.") % {
|
||||
'method_name': payment_del
|
||||
}
|
||||
)
|
||||
except ProtectedError as err:
|
||||
messages_protected_error(messages, request, payment_del, err)
|
||||
return redirect(reverse('cotisations:index-paiement'))
|
||||
return form({
|
||||
'factureform': payment,
|
||||
|
@ -606,14 +600,8 @@ def del_banque(request, instances):
|
|||
'bank_name': bank_del
|
||||
}
|
||||
)
|
||||
except ProtectedError:
|
||||
messages.error(
|
||||
request,
|
||||
_("The bank %(bank_name)s can't be deleted \
|
||||
because there are invoices using it.") % {
|
||||
'bank_name': bank_del
|
||||
}
|
||||
)
|
||||
except ProtectedError as err:
|
||||
messages_protected_error(messages, request, bank_del, err)
|
||||
return redirect(reverse('cotisations:index-banque'))
|
||||
return form({
|
||||
'factureform': bank,
|
||||
|
|
|
@ -39,6 +39,8 @@ from django.contrib.auth.decorators import login_required, permission_required
|
|||
from django.db.models import ProtectedError, F
|
||||
from django.forms import modelformset_factory
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
|
||||
from rest_framework.renderers import JSONRenderer
|
||||
|
||||
|
@ -49,6 +51,7 @@ from re2o.utils import (
|
|||
filter_active_interfaces,
|
||||
SortTable,
|
||||
re2o_paginator,
|
||||
messages_protected_error,
|
||||
)
|
||||
from re2o.acl import (
|
||||
can_create,
|
||||
|
@ -504,12 +507,8 @@ def del_iptype(request, instances):
|
|||
try:
|
||||
iptype_del.delete()
|
||||
messages.success(request, "Le type d'ip a été supprimé")
|
||||
except ProtectedError:
|
||||
messages.error(
|
||||
request,
|
||||
("Le type d'ip %s est affectée à au moins une machine, "
|
||||
"vous ne pouvez pas le supprimer" % iptype_del)
|
||||
)
|
||||
except ProtectedError as err:
|
||||
messages_protected_error(messages, request, iptype_del, err)
|
||||
return redirect(reverse('machines:index-iptype'))
|
||||
return form(
|
||||
{'iptypeform': iptype, 'action_name': 'Supprimer'},
|
||||
|
@ -565,13 +564,8 @@ def del_machinetype(request, instances):
|
|||
try:
|
||||
machinetype_del.delete()
|
||||
messages.success(request, "Le type de machine a été supprimé")
|
||||
except ProtectedError:
|
||||
messages.error(
|
||||
request,
|
||||
("Le type de machine %s est affectée à au moins une "
|
||||
"machine, vous ne pouvez pas le supprimer"
|
||||
% machinetype_del)
|
||||
)
|
||||
except ProtectedError as err:
|
||||
messages_protected_error(messages, request, machinetype_del, err)
|
||||
return redirect(reverse('machines:index-machinetype'))
|
||||
return form(
|
||||
{'machinetypeform': machinetype, 'action_name': 'Supprimer'},
|
||||
|
@ -627,13 +621,8 @@ def del_extension(request, instances):
|
|||
try:
|
||||
extension_del.delete()
|
||||
messages.success(request, "L'extension a été supprimée")
|
||||
except ProtectedError:
|
||||
messages.error(
|
||||
request,
|
||||
("L'extension %s est affectée à au moins un type de "
|
||||
"machine, vous ne pouvez pas la supprimer"
|
||||
% extension_del)
|
||||
)
|
||||
except ProtectedError as err:
|
||||
messages_protected_error(messages, request, extension_del, err)
|
||||
return redirect(reverse('machines:index-extension'))
|
||||
return form(
|
||||
{'extensionform': extension, 'action_name': 'Supprimer'},
|
||||
|
@ -686,12 +675,8 @@ def del_soa(request, instances):
|
|||
try:
|
||||
soa_del.delete()
|
||||
messages.success(request, "Le SOA a été supprimée")
|
||||
except ProtectedError:
|
||||
messages.error(
|
||||
request,
|
||||
("Erreur le SOA suivant %s ne peut être supprimé"
|
||||
% soa_del)
|
||||
)
|
||||
except ProtectedError as err:
|
||||
messages_protected_error(messages, request, soa_del, err)
|
||||
return redirect(reverse('machines:index-extension'))
|
||||
return form(
|
||||
{'soaform': soa, 'action_name': 'Supprimer'},
|
||||
|
@ -744,12 +729,8 @@ def del_mx(request, instances):
|
|||
try:
|
||||
mx_del.delete()
|
||||
messages.success(request, "L'mx a été supprimée")
|
||||
except ProtectedError:
|
||||
messages.error(
|
||||
request,
|
||||
("Erreur le Mx suivant %s ne peut être supprimé"
|
||||
% mx_del)
|
||||
)
|
||||
except ProtectedError as err:
|
||||
messages_protected_error(messages, request, mx_del, err)
|
||||
return redirect(reverse('machines:index-extension'))
|
||||
return form(
|
||||
{'mxform': mx, 'action_name': 'Supprimer'},
|
||||
|
@ -802,12 +783,8 @@ def del_ns(request, instances):
|
|||
try:
|
||||
ns_del.delete()
|
||||
messages.success(request, "Le ns a été supprimée")
|
||||
except ProtectedError:
|
||||
messages.error(
|
||||
request,
|
||||
("Erreur le Ns suivant %s ne peut être supprimé"
|
||||
% ns_del)
|
||||
)
|
||||
except ProtectedError as err:
|
||||
messages_protected_error(messages, request, ns_del, err)
|
||||
return redirect(reverse('machines:index-extension'))
|
||||
return form(
|
||||
{'nsform': ns, 'action_name': 'Supprimer'},
|
||||
|
@ -860,12 +837,8 @@ def del_txt(request, instances):
|
|||
try:
|
||||
txt_del.delete()
|
||||
messages.success(request, "Le txt a été supprimé")
|
||||
except ProtectedError:
|
||||
messages.error(
|
||||
request,
|
||||
("Erreur le Txt suivant %s ne peut être supprimé"
|
||||
% txt_del)
|
||||
)
|
||||
except ProtectedError as err:
|
||||
messages_protected_error(messages, request, txt_del, err)
|
||||
return redirect(reverse('machines:index-extension'))
|
||||
return form(
|
||||
{'txtform': txt, 'action_name': 'Supprimer'},
|
||||
|
@ -918,12 +891,8 @@ def del_srv(request, instances):
|
|||
try:
|
||||
srv_del.delete()
|
||||
messages.success(request, "L'srv a été supprimée")
|
||||
except ProtectedError:
|
||||
messages.error(
|
||||
request,
|
||||
("Erreur le Srv suivant %s ne peut être supprimé"
|
||||
% srv_del)
|
||||
)
|
||||
except ProtectedError as err:
|
||||
messages_protected_error(messages, request, srv_del, err)
|
||||
return redirect(reverse('machines:index-extension'))
|
||||
return form(
|
||||
{'srvform': srv, 'action_name': 'Supprimer'},
|
||||
|
@ -994,12 +963,8 @@ def del_alias(request, interface, interfaceid):
|
|||
request,
|
||||
"L'alias %s a été supprimé" % alias_del
|
||||
)
|
||||
except ProtectedError:
|
||||
messages.error(
|
||||
request,
|
||||
("Erreur l'alias suivant %s ne peut être supprimé"
|
||||
% alias_del)
|
||||
)
|
||||
except ProtectedError as err:
|
||||
messages_protected_error(messages, request, alias_del, err)
|
||||
return redirect(reverse(
|
||||
'machines:index-alias',
|
||||
kwargs={'interfaceid': str(interfaceid)}
|
||||
|
@ -1055,12 +1020,8 @@ def del_service(request, instances):
|
|||
try:
|
||||
service_del.delete()
|
||||
messages.success(request, "Le service a été supprimée")
|
||||
except ProtectedError:
|
||||
messages.error(
|
||||
request,
|
||||
("Erreur le service suivant %s ne peut être supprimé"
|
||||
% service_del)
|
||||
)
|
||||
except ProtectedError as err:
|
||||
messages_protected_error(messages, request, service_del, err)
|
||||
return redirect(reverse('machines:index-service'))
|
||||
return form(
|
||||
{'serviceform': service, 'action_name': 'Supprimer'},
|
||||
|
@ -1113,12 +1074,8 @@ def del_vlan(request, instances):
|
|||
try:
|
||||
vlan_del.delete()
|
||||
messages.success(request, "Le vlan a été supprimée")
|
||||
except ProtectedError:
|
||||
messages.error(
|
||||
request,
|
||||
("Erreur le Vlan suivant %s ne peut être supprimé"
|
||||
% vlan_del)
|
||||
)
|
||||
except ProtectedError as err:
|
||||
messages_protected_error(messages, request, vlan_del, err)
|
||||
return redirect(reverse('machines:index-vlan'))
|
||||
return form(
|
||||
{'vlanform': vlan, 'action_name': 'Supprimer'},
|
||||
|
@ -1171,12 +1128,8 @@ def del_nas(request, instances):
|
|||
try:
|
||||
nas_del.delete()
|
||||
messages.success(request, "Le nas a été supprimé")
|
||||
except ProtectedError:
|
||||
messages.error(
|
||||
request,
|
||||
("Erreur le Nas suivant %s ne peut être supprimé"
|
||||
% nas_del)
|
||||
)
|
||||
except ProtectedError as err:
|
||||
messages_protected_error(messages, request, nas_del, err)
|
||||
return redirect(reverse('machines:index-nas'))
|
||||
return form(
|
||||
{'nasform': nas, 'action_name': 'Supprimer'},
|
||||
|
|
|
@ -36,11 +36,13 @@ from django.contrib import messages
|
|||
from django.contrib.auth.decorators import login_required
|
||||
from django.db.models import ProtectedError
|
||||
from django.db import transaction
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
from reversion import revisions as reversion
|
||||
|
||||
from re2o.views import form
|
||||
from re2o.acl import can_create, can_edit, can_delete_set, can_view_all
|
||||
from re2o.utils import messages_protected_error
|
||||
|
||||
from .forms import ServiceForm, DelServiceForm
|
||||
from .models import (
|
||||
|
@ -180,9 +182,8 @@ def del_services(request, instances):
|
|||
services_del.delete()
|
||||
reversion.set_user(request.user)
|
||||
messages.success(request, "Le service a été supprimée")
|
||||
except ProtectedError:
|
||||
messages.error(request, "Erreur le service\
|
||||
suivant %s ne peut être supprimé" % services_del)
|
||||
except ProtectedError as err:
|
||||
messages_protected_error(messages, request, service_del, err)
|
||||
return redirect(reverse('preferences:display-options'))
|
||||
return form(
|
||||
{'preferenceform': services, 'action_name': 'Supprimer'},
|
||||
|
|
|
@ -47,11 +47,12 @@ from django.template.loader import get_template
|
|||
from django.template import Context, Template, loader
|
||||
from django.db.models.signals import post_save
|
||||
from django.dispatch import receiver
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
import tempfile
|
||||
|
||||
from users.views import form
|
||||
from re2o.utils import re2o_paginator, SortTable
|
||||
from re2o.utils import re2o_paginator, SortTable, messages_protected_error
|
||||
from re2o.acl import (
|
||||
can_create,
|
||||
can_edit,
|
||||
|
@ -350,12 +351,8 @@ def del_port(request, port, **_kwargs):
|
|||
try:
|
||||
port.delete()
|
||||
messages.success(request, "Le port a été détruit")
|
||||
except ProtectedError:
|
||||
messages.error(
|
||||
request,
|
||||
("Le port %s est affecté à un autre objet, impossible "
|
||||
"de le supprimer" % port)
|
||||
)
|
||||
except ProtectedError as err:
|
||||
messages_protected_error(messages, request, port, err)
|
||||
return redirect(reverse(
|
||||
'topologie:index-port',
|
||||
kwargs={'switchid': str(port.switch.id)}
|
||||
|
@ -404,11 +401,7 @@ def del_stack(request, stack, **_kwargs):
|
|||
stack.delete()
|
||||
messages.success(request, "La stack a eté détruite")
|
||||
except ProtectedError:
|
||||
messages.error(
|
||||
request,
|
||||
("La stack %s est affectée à un autre objet, impossible "
|
||||
"de la supprimer" % stack)
|
||||
)
|
||||
messages_protected_error(messages, request, satck, err)
|
||||
return redirect(reverse('topologie:index-physical-grouping'))
|
||||
return form({'objet': stack}, 'topologie/delete.html', request)
|
||||
|
||||
|
@ -715,11 +708,7 @@ def del_room(request, room, **_kwargs):
|
|||
room.delete()
|
||||
messages.success(request, "La chambre/prise a été détruite")
|
||||
except ProtectedError:
|
||||
messages.error(
|
||||
request,
|
||||
("La chambre %s est affectée à un autre objet, impossible "
|
||||
"de la supprimer (switch ou user)" % room)
|
||||
)
|
||||
messages_protected_error(messages, request, room, err)
|
||||
return redirect(reverse('topologie:index-room'))
|
||||
return form(
|
||||
{'objet': room, 'objet_name': 'Chambre'},
|
||||
|
@ -774,11 +763,7 @@ def del_model_switch(request, model_switch, **_kwargs):
|
|||
model_switch.delete()
|
||||
messages.success(request, "Le modèle a été détruit")
|
||||
except ProtectedError:
|
||||
messages.error(
|
||||
request,
|
||||
("Le modèle %s est affectée à un autre objet, impossible "
|
||||
"de la supprimer (switch ou user)" % model_switch)
|
||||
)
|
||||
messages_protected_error(messages, request, model_switch, err)
|
||||
return redirect(reverse('topologie:index-model-switch'))
|
||||
return form(
|
||||
{'objet': model_switch, 'objet_name': 'Modèle de switch'},
|
||||
|
@ -829,11 +814,7 @@ def del_switch_bay(request, switch_bay, **_kwargs):
|
|||
switch_bay.delete()
|
||||
messages.success(request, "La baie a été détruite")
|
||||
except ProtectedError:
|
||||
messages.error(
|
||||
request,
|
||||
("La baie %s est affecté à un autre objet, impossible "
|
||||
"de la supprimer (switch ou user)" % switch_bay)
|
||||
)
|
||||
messages_protected_error(messages, request, switch_bay, err)
|
||||
return redirect(reverse('topologie:index-physical-grouping'))
|
||||
return form(
|
||||
{'objet': switch_bay, 'objet_name': 'Baie de switch'},
|
||||
|
@ -883,12 +864,8 @@ def del_building(request, building, **_kwargs):
|
|||
try:
|
||||
building.delete()
|
||||
messages.success(request, "La batiment a été détruit")
|
||||
except ProtectedError:
|
||||
messages.error(
|
||||
request,
|
||||
("Le batiment %s est affecté à un autre objet, impossible "
|
||||
"de la supprimer (switch ou user)" % building)
|
||||
)
|
||||
except ProtectedError as err:
|
||||
messages_protected_error(messages, request, building, err)
|
||||
return redirect(reverse('topologie:index-physical-grouping'))
|
||||
return form(
|
||||
{'objet': building, 'objet_name': 'Bâtiment'},
|
||||
|
@ -943,11 +920,7 @@ def del_constructor_switch(request, constructor_switch, **_kwargs):
|
|||
constructor_switch.delete()
|
||||
messages.success(request, "Le constructeur a été détruit")
|
||||
except ProtectedError:
|
||||
messages.error(
|
||||
request,
|
||||
("Le constructeur %s est affecté à un autre objet, impossible "
|
||||
"de la supprimer (switch ou user)" % constructor_switch)
|
||||
)
|
||||
messages_protected_error(messages, request, constructor_switch, err)
|
||||
return redirect(reverse('topologie:index-model-switch'))
|
||||
return form({
|
||||
'objet': constructor_switch,
|
||||
|
|
|
@ -45,6 +45,7 @@ from django.db import transaction
|
|||
from django.http import HttpResponse
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
from rest_framework.renderers import JSONRenderer
|
||||
from reversion import revisions as reversion
|
||||
|
@ -56,7 +57,8 @@ from re2o.views import form
|
|||
from re2o.utils import (
|
||||
all_has_access,
|
||||
SortTable,
|
||||
re2o_paginator
|
||||
re2o_paginator,
|
||||
messages_protected_error
|
||||
)
|
||||
from re2o.acl import (
|
||||
can_create,
|
||||
|
@ -510,10 +512,7 @@ def del_school(request, instances):
|
|||
school_del.delete()
|
||||
messages.success(request, "L'établissement a été supprimé")
|
||||
except ProtectedError:
|
||||
messages.error(
|
||||
request,
|
||||
"L'établissement %s est affecté à au moins un user, \
|
||||
vous ne pouvez pas le supprimer" % school_del)
|
||||
messages_protected_error(messages, request, school_del, err)
|
||||
return redirect(reverse('users:index-school'))
|
||||
return form(
|
||||
{'userform': school, 'action_name': 'Supprimer'},
|
||||
|
@ -621,10 +620,7 @@ def del_listright(request, instances):
|
|||
listright_del.delete()
|
||||
messages.success(request, "Le droit/groupe a été supprimé")
|
||||
except ProtectedError:
|
||||
messages.error(
|
||||
request,
|
||||
"Le groupe %s est affecté à au moins un user, \
|
||||
vous ne pouvez pas le supprimer" % listright_del)
|
||||
messages_protected_error(messages, request, listright_del, err)
|
||||
return redirect(reverse('users:index-listright'))
|
||||
return form(
|
||||
{'userform': listright, 'action_name': 'Supprimer'},
|
||||
|
|
Loading…
Reference in a new issue