Commit 0ab78860 authored by Daniel STAN's avatar Daniel STAN

machines: plus d'info sur les erreurs (messages)

parent 5fa49a95
......@@ -91,7 +91,7 @@ class Machine(dict):
if self.machine:
self.mode = self.machine.mode
if self.machine.proprio().dn != self.luser.dn and not self.machine.proprio().dn in [ cl.dn for cl in self.luser.clubs()]:
raise ValueError("Aucun droit sur la machine")
raise ValueError("Aucun droit sur la machine %s" % self.machine['mid'][0])
self.update(self._get_machine_info())
def delete(self, attr, index):
......
......@@ -7,7 +7,7 @@ from django.contrib.auth.decorators import login_required
from django.template import RequestContext
from lc_ldap.ldap_locks import LockError
from django.contrib import messages
from django.utils.importlib import import_module
conn_pool = import_module('conn_pool', 'intranet')
......@@ -62,11 +62,14 @@ def index(request):
@login_required
def detail(request, mid=None):
if request.method == "GET":
machine = models.Machine(user=request.user, mid=mid)
if not machine:
return redirect('machines:index')
return render(request, 'machines/detail.html', {'machine' : machine})
try:
machine = models.Machine(user=request.user, mid=mid)
if not machine:
return redirect('machines:index')
return render(request, 'machines/detail.html', {'machine' : machine})
except (ValueError, EnvironmentError, LockError) as error:
messages.error(request, 'Erreur : %s' % unicode_of_Error(error))
return redirect("machines:index")
else:
print request.POST
......@@ -110,7 +113,17 @@ def ssh_keys(request, mid=None, delete=None):
@login_required
def delete(request, mid=None):
if mid:
models.delete_machine(request.user, mid)
try:
models.delete_machine(request.user, mid)
except (ValueError, EnvironmentError, LockError) as error:
try:
machine = models.Machine(user=request.user, mid=mid)
return render(request, 'machines/detail.html', {
'machine' : machine,
'error' : 'Erreur : %s' % unicode_of_Error(error)})
except (ValueError, EnvironmentError, LockError) as error:
messages.error(request, 'Erreur : %s' % unicode_of_Error(error))
return redirect("machines:index")
@login_required
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment