Merge "Show workbook definition"

This commit is contained in:
Jenkins 2015-07-13 08:33:20 +00:00 committed by Gerrit Code Review
commit d9434fd3a0
5 changed files with 58 additions and 3 deletions

View File

@ -88,3 +88,12 @@ def workbook_list(request):
"""Returns all workbooks."""
return mistralclient(request).workbooks.list()
def workbook_get(request, workbook_name):
"""Get specific workbook.
:param workbook_name: Workbook name
"""
return mistralclient(request).workbooks.get(workbook_name)

View File

@ -25,7 +25,11 @@ def tags_to_string(workbook):
class WorkbooksTable(tables.DataTable):
name = tables.Column("name", verbose_name=_("Name"))
name = tables.Column(
"name",
verbose_name=_("Name"),
link="horizon:mistral:workbooks:detail"
)
tags = tables.Column(tags_to_string, verbose_name=_("Tags"))
created = tables.Column(
"created_at",

View File

@ -0,0 +1,13 @@
{% extends 'base.html' %}
{% load i18n %}
{% block title %}{% trans "Workbook Definition" %}{% endblock %}
{% block page_header %}
{% include "horizon/common/_page_header.html" with title=_("Workbook Definition") %}
{% endblock page_header %}
{% block main %}
<div class="detail">
<pre>{{ definition }}</pre>
</div>
{% endblock %}

View File

@ -17,11 +17,12 @@
from django.conf.urls import patterns # noqa
from django.conf.urls import url # noqa
from mistraldashboard.workbooks.views import IndexView
from mistraldashboard.workbooks import views
WORKBOOKS = r'^(?P<workbook_name>[^/]+)/%s$'
urlpatterns = patterns(
'',
url(r'^$', IndexView.as_view(), name='index'),
url(r'^$', views.IndexView.as_view(), name='index'),
url(WORKBOOKS % 'detail', views.DetailView.as_view(), name='detail'),
)

View File

@ -14,6 +14,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext_lazy as _
from django.views import generic
from horizon import exceptions
from horizon import tables
from mistraldashboard import api
@ -26,3 +31,26 @@ class IndexView(tables.DataTableView):
def get_data(self):
return api.workbook_list(self.request)
class DetailView(generic.TemplateView):
template_name = 'mistral/workbooks/detail.html'
page_title = _("Workbook Definition")
def get_context_data(self, **kwargs):
context = super(DetailView, self).get_context_data(**kwargs)
workbook = self.get_data(self.request, **kwargs)
context['definition'] = workbook.definition
return context
def get_data(self, request, **kwargs):
try:
workbook_name = kwargs['workbook_name']
workbook = api.workbook_get(request, workbook_name)
except Exception:
msg = _('Unable to get workbook "%s".') % workbook_name
redirect = reverse('horizon:mistral:workbooks:index')
exceptions.handle(self.request, msg, redirect=redirect)
return workbook