Error message for invalid cluster details page

Using an invalid cluster ID for cluster details URL causes a stack trace.
This patch adds a proper error message for this case.

Closes-Bug: #1463838

Change-Id: I2867a2aceebf7def99be59d337f3aa8984dfd98a
This commit is contained in:
Tatiana Ovchinnikova 2015-06-18 14:04:35 +03:00
parent dc3d7e57f9
commit 2180e40457

View File

@ -18,6 +18,8 @@ from django.utils.translation import ugettext_lazy as _
from horizon import exceptions
from horizon import tables
from horizon import tabs
from horizon.utils import memoized
from horizon.utils.urlresolvers import reverse # noqa
from horizon import workflows
from openstack_dashboard.api import sahara as saharaclient
@ -58,9 +60,20 @@ class ClusterDetailsView(tabs.TabView):
template_name = 'project/data_processing.clusters/details.html'
page_title = _("Cluster Details")
@memoized.memoized_method
def get_object(self):
cl_id = self.kwargs["cluster_id"]
try:
return saharaclient.cluster_get(self.request, cl_id)
except Exception:
msg = _('Unable to retrieve details for cluster "%s".') % cl_id
redirect = reverse(
"horizon:project:data_processing.clusters:clusters")
exceptions.handle(self.request, msg, redirect=redirect)
def get_context_data(self, **kwargs):
context = super(ClusterDetailsView, self)\
.get_context_data(**kwargs)
context = super(ClusterDetailsView, self).get_context_data(**kwargs)
context['cluster'] = self.get_object()
return context