Show Action definition

Partially implements blueprint mistral-dashboard-crud-operations

Change-Id: Ib275d2fb772278d081af69c56dca9d78c46c127c
This commit is contained in:
Zhenguo Niu 2015-08-01 09:53:49 +08:00
parent c4822e3314
commit c85c3a6bbe
5 changed files with 57 additions and 1 deletions

View File

@ -32,7 +32,11 @@ def cut(action, length=100):
class ActionsTable(tables.DataTable):
name = tables.Column("name", verbose_name=_("Name"))
name = tables.Column(
"name",
verbose_name=_("Name"),
link="horizon:mistral:actions:detail"
)
description = tables.Column("description", verbose_name=_("Description"))
is_system = tables.Column("is_system", verbose_name=_("Is System"))
tags = tables.Column(tags_to_string, verbose_name=_("Tags"))

View File

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

View File

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

View File

@ -12,6 +12,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.actions.tables import ActionsTable
@ -24,3 +29,26 @@ class IndexView(tables.DataTableView):
def get_data(self):
return api.action_list(self.request)
class DetailView(generic.TemplateView):
template_name = 'mistral/actions/detail.html'
page_title = _("Action Definition")
def get_context_data(self, **kwargs):
context = super(DetailView, self).get_context_data(**kwargs)
action = self.get_data(self.request, **kwargs)
context['definition'] = action.definition
return context
def get_data(self, request, **kwargs):
try:
action_name = kwargs['action_name']
action = api.action_get(request, action_name)
except Exception:
msg = _('Unable to get action "%s".') % action_name
redirect = reverse('horizon:mistral:actions:index')
exceptions.handle(self.request, msg, redirect=redirect)
return action

View File

@ -194,3 +194,12 @@ def action_list(request):
"""Returns all actions."""
return mistralclient(request).actions.list()
def action_get(request, action_name):
"""Get specific action.
:param action_name: Action name
"""
return mistralclient(request).actions.get(action_name)