diff --git a/mistraldashboard/actions/tables.py b/mistraldashboard/actions/tables.py index 3e10bfb..ca35056 100644 --- a/mistraldashboard/actions/tables.py +++ b/mistraldashboard/actions/tables.py @@ -90,9 +90,18 @@ class ActionsTable(tables.DataTable): verbose_name=_("Name"), link="horizon:mistral:actions:detail" ) - is_system = tables.Column("is_system", verbose_name=_("Is System")) - tags = tables.Column(tags_to_string, verbose_name=_("Tags")) - inputs = tables.Column(cut, verbose_name=_("Input")) + is_system = tables.Column( + "is_system", + verbose_name=_("Is System") + ) + tags = tables.Column( + tags_to_string, + verbose_name=_("Tags") + ) + inputs = tables.Column( + cut, + verbose_name=_("Input") + ) created = tables.Column( "created_at", verbose_name=_("Created"), @@ -110,9 +119,6 @@ class ActionsTable(tables.DataTable): ) ) - def get_object_id(self, datum): - return datum.name - class Meta(object): name = "actions" verbose_name = _("Actions") diff --git a/mistraldashboard/actions/templates/actions/index.html b/mistraldashboard/actions/templates/actions/index.html index 185c37b..b50a6b1 100644 --- a/mistraldashboard/actions/templates/actions/index.html +++ b/mistraldashboard/actions/templates/actions/index.html @@ -1,11 +1,7 @@ -{% extends 'mistral/default/base.html' %} +{% extends 'mistral/default/table.html' %} {% load i18n %} {% block title %}{% trans "Actions" %}{% endblock %} {% block page_header %} {% include "horizon/common/_page_header.html" with title=_("Actions") %} -{% endblock page_header %} - -{% block main %} - {{ table.render }} -{% endblock %} +{% endblock page_header %} \ No newline at end of file diff --git a/mistraldashboard/actions/views.py b/mistraldashboard/actions/views.py index b40d8fd..0c02549 100644 --- a/mistraldashboard/actions/views.py +++ b/mistraldashboard/actions/views.py @@ -49,11 +49,59 @@ class UpdateView(forms.ModalFormView): class IndexView(tables.DataTableView): + table_id = "workflow_action" table_class = ActionsTable template_name = 'mistral/actions/index.html' + def has_prev_data(self, table): + return self._prev + + def has_more_data(self, table): + return self._more + def get_data(self): - return api.action_list(self.request) + actions = [] + prev_marker = self.request.GET.get( + ActionsTable._meta.prev_pagination_param, + None + ) + + if prev_marker is not None: + sort_dir = 'asc' + marker = prev_marker + else: + sort_dir = 'desc' + marker = self.request.GET.get( + ActionsTable._meta.pagination_param, + None + ) + + try: + actions, self._more, self._prev = api.pagination_list( + entity="actions", + request=self.request, + marker=marker, + sort_keys='name', + sort_dirs=sort_dir, + paginate=True + ) + + if prev_marker is not None: + actions = sorted( + actions, + key=lambda action: getattr( + action, 'name' + ), + reverse=True + ) + + except Exception as e: + self._prev = False + self._more = False + msg = _('Unable to retrieve actions list: %s') % str(e) + exceptions.handle(self.request, msg) + + return actions class DetailView(generic.TemplateView): diff --git a/mistraldashboard/api.py b/mistraldashboard/api.py index e24eacd..89f007e 100644 --- a/mistraldashboard/api.py +++ b/mistraldashboard/api.py @@ -48,15 +48,16 @@ def mistralclient(request): @handle_errors(_("Unable to retrieve list"), []) def pagination_list(entity, request, marker='', sort_keys='', - sort_dirs='', paginate=False): + sort_dirs='asc', paginate=False): """Retrieve a listing of specific entity and handles pagination. :param entity: Requested entity (String) :param request: Request data :param marker: Pagination marker for large data sets: entity id - :param sort_keys: Columns to sort results by. Default: created_at + :param sort_keys: Columns to sort results by :param sort_dirs: Sorting Directions (asc/desc). Default:asc - :param paginate: If true will perform pagination based on settings + :param paginate: If true will perform pagination based on settings. + Default:False """ limit = getattr(settings, 'API_RESULT_LIMIT', 1000) @@ -67,8 +68,8 @@ def pagination_list(entity, request, marker='', sort_keys='', else: request_size = limit - request = mistralclient(request) - entities_iter = (eval('request.%s' % entity)).list( + api = mistralclient(request) + entities_iter = getattr(api, entity).list( marker, limit, sort_keys, sort_dirs ) diff --git a/mistraldashboard/default/templates/default/table.html b/mistraldashboard/default/templates/default/table.html index 04d3b6b..38b3ff6 100644 --- a/mistraldashboard/default/templates/default/table.html +++ b/mistraldashboard/default/templates/default/table.html @@ -1,5 +1,7 @@ {% extends 'mistral/default/base.html' %} {% block main %} +
{{ table.render }} +
{% endblock %} diff --git a/mistraldashboard/executions/templates/executions/index.html b/mistraldashboard/executions/templates/executions/index.html index 2969a5c..1fa7452 100644 --- a/mistraldashboard/executions/templates/executions/index.html +++ b/mistraldashboard/executions/templates/executions/index.html @@ -1,11 +1,7 @@ -{% extends 'mistral/default/base.html' %} +{% extends 'mistral/default/table.html' %} {% load i18n %} {% block title %}{% trans "Executions" %}{% endblock %} {% block page_header %} {% include "horizon/common/_page_header.html" with title=_("Executions") %} {% endblock page_header %} - -{% block main %} - {{ table.render }} -{% endblock %} diff --git a/mistraldashboard/static/mistraldashboard/css/style.css b/mistraldashboard/static/mistraldashboard/css/style.css index 37a5e7c..7c6d011 100644 --- a/mistraldashboard/static/mistraldashboard/css/style.css +++ b/mistraldashboard/static/mistraldashboard/css/style.css @@ -1,3 +1,11 @@ .list{ list-style: inherit; +} + +.mistral-wrapper #actions{ + width:100%; +} + +.mistral-wrapper #actions a.btn{ + width:inherit; } \ No newline at end of file diff --git a/mistraldashboard/workbooks/templates/workbooks/index.html b/mistraldashboard/workbooks/templates/workbooks/index.html index 001447e..6eb3cf3 100644 --- a/mistraldashboard/workbooks/templates/workbooks/index.html +++ b/mistraldashboard/workbooks/templates/workbooks/index.html @@ -1,11 +1,7 @@ -{% extends 'mistral/default/base.html' %} +{% extends 'mistral/default/table.html' %} {% load i18n %} {% block title %}{% trans "Workbooks" %}{% endblock %} {% block page_header %} {% include "horizon/common/_page_header.html" with title=_("Workbooks") %} {% endblock page_header %} - -{% block main %} - {{ table.render }} -{% endblock %} diff --git a/mistraldashboard/workflows/forms.py b/mistraldashboard/workflows/forms.py index e56ee10..49ea6d8 100644 --- a/mistraldashboard/workflows/forms.py +++ b/mistraldashboard/workflows/forms.py @@ -50,8 +50,8 @@ class ExecuteForm(forms.SelfHandlingForm): messages.success(request, msg) return True - except Exception: - msg = _('Failed to execute workflow "%s".') % data['workflow_name'] + except Exception as e: + msg = _('Failed to execute workflow "%s".') % e redirect = reverse('horizon:mistral:workflows:index') exceptions.handle(request, msg, redirect=redirect) diff --git a/mistraldashboard/workflows/templates/workflows/index.html b/mistraldashboard/workflows/templates/workflows/index.html index b689744..9a2b4fe 100644 --- a/mistraldashboard/workflows/templates/workflows/index.html +++ b/mistraldashboard/workflows/templates/workflows/index.html @@ -1,11 +1,7 @@ -{% extends 'mistral/default/base.html' %} +{% extends 'mistral/default/table.html' %} {% load i18n %} {% block title %}{% trans "Workflows" %}{% endblock %} {% block page_header %} {% include "horizon/common/_page_header.html" with title=_("Workflows") %} {% endblock page_header %} - -{% block main %} - {{ table.render }} -{% endblock %}