From ca630e652fd64b1a4c556a2b49f7c1f071b52d4f Mon Sep 17 00:00:00 2001 From: lawrancejing Date: Tue, 24 Nov 2015 14:17:48 +0000 Subject: [PATCH] Add workflow panel Change-Id: I81307a5a532123528ff2ab9616e7b5e3c5091bf7 --- _99_evoque.py.example | 2 +- evoque_dashboard/api/__init__.py | 0 evoque_dashboard/api/evoque.py | 47 +++++++++++++++++++ evoque_dashboard/dashboard.py | 25 ++++++++++ evoque_dashboard/workflows/__init__.py | 0 evoque_dashboard/workflows/panel.py | 25 ++++++++++ evoque_dashboard/workflows/tables.py | 41 ++++++++++++++++ .../workflows/templates/workflows/index.html | 11 +++++ evoque_dashboard/workflows/urls.py | 22 +++++++++ evoque_dashboard/workflows/views.py | 33 +++++++++++++ test-requirements.txt | 1 + 11 files changed, 206 insertions(+), 1 deletion(-) create mode 100644 evoque_dashboard/api/__init__.py create mode 100644 evoque_dashboard/api/evoque.py create mode 100644 evoque_dashboard/dashboard.py create mode 100644 evoque_dashboard/workflows/__init__.py create mode 100644 evoque_dashboard/workflows/panel.py create mode 100644 evoque_dashboard/workflows/tables.py create mode 100644 evoque_dashboard/workflows/templates/workflows/index.html create mode 100644 evoque_dashboard/workflows/urls.py create mode 100644 evoque_dashboard/workflows/views.py diff --git a/_99_evoque.py.example b/_99_evoque.py.example index 4a098fd..8b6ae3e 100644 --- a/_99_evoque.py.example +++ b/_99_evoque.py.example @@ -1,4 +1,4 @@ -from evoquedashboard import exceptions +from evoque_dashboard import exceptions DASHBOARD = 'ticket' ADD_INSTALLED_APPS = [ diff --git a/evoque_dashboard/api/__init__.py b/evoque_dashboard/api/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/evoque_dashboard/api/evoque.py b/evoque_dashboard/api/evoque.py new file mode 100644 index 0000000..2c29031 --- /dev/null +++ b/evoque_dashboard/api/evoque.py @@ -0,0 +1,47 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from django.conf import settings + +from horizon.utils import memoized + +from openstack_dashboard.api import base + +from evoqueclient import client as evoque_client + +USER_AGENT = 'python-senlinclient' + + +class Workflow(base.APIResourceWrapper): + _attrs = ['id', 'name', 'created_at', 'updated_at'] + + +def _get_endpoint(request): + endpoint = getattr( + settings, 'EVOQUE_API_URL', "http://127.0.0.1:8808") + + return endpoint + + +@memoized.memoized +def evoqueclient(request): + endpoint = _get_endpoint(request) + + return evoque_client.Client(1, endpoint=endpoint, + token=request.user.token.id, + tenant=request.user.tenant_id) + + +def workflow_list(request): + """Returns all workflows.""" + workflows = evoqueclient(request).workflows.list() + return [Workflow(c) for c in workflows] diff --git a/evoque_dashboard/dashboard.py b/evoque_dashboard/dashboard.py new file mode 100644 index 0000000..e47eb8a --- /dev/null +++ b/evoque_dashboard/dashboard.py @@ -0,0 +1,25 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from django.utils.translation import ugettext_lazy as _ + +import horizon + + +class Ticket(horizon.Dashboard): + name = _("Ticket") + slug = "ticket" + panels = ('workflows',) + default_panel = 'workflows' + + +horizon.register(Ticket) diff --git a/evoque_dashboard/workflows/__init__.py b/evoque_dashboard/workflows/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/evoque_dashboard/workflows/panel.py b/evoque_dashboard/workflows/panel.py new file mode 100644 index 0000000..736e475 --- /dev/null +++ b/evoque_dashboard/workflows/panel.py @@ -0,0 +1,25 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from django.utils.translation import ugettext_lazy as _ + +import horizon + +from evoque_dashboard import dashboard + + +class Workflows(horizon.Panel): + name = _("Workflows") + slug = 'workflows' + + +dashboard.Ticket.register(Workflows) diff --git a/evoque_dashboard/workflows/tables.py b/evoque_dashboard/workflows/tables.py new file mode 100644 index 0000000..3c6059c --- /dev/null +++ b/evoque_dashboard/workflows/tables.py @@ -0,0 +1,41 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from django.utils.translation import ugettext_lazy as _ + +from horizon import tables +from horizon.utils import filters + + +class WorkflowsTable(tables.DataTable): + name = tables.Column("name", verbose_name=_("Name")) + created = tables.Column( + "created_at", + verbose_name=_("Created"), + filters=( + filters.parse_isotime, + filters.timesince_or_never + ) + ) + updated = tables.Column( + "updated_at", + verbose_name=_("Updated"), + filters=( + filters.parse_isotime, + filters.timesince_or_never + ) + ) + + class Meta(object): + name = "workflows" + verbose_name = _("Workflows") + table_actions = (tables.FilterAction,) diff --git a/evoque_dashboard/workflows/templates/workflows/index.html b/evoque_dashboard/workflows/templates/workflows/index.html new file mode 100644 index 0000000..2a22732 --- /dev/null +++ b/evoque_dashboard/workflows/templates/workflows/index.html @@ -0,0 +1,11 @@ +{% extends 'base.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 %} diff --git a/evoque_dashboard/workflows/urls.py b/evoque_dashboard/workflows/urls.py new file mode 100644 index 0000000..a27eb93 --- /dev/null +++ b/evoque_dashboard/workflows/urls.py @@ -0,0 +1,22 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from django.conf.urls import patterns # noqa +from django.conf.urls import url # noqa + +from evoque_dashboard.workflows import views + + +urlpatterns = patterns( + '', + url(r'^$', views.IndexView.as_view(), name='index'), +) diff --git a/evoque_dashboard/workflows/views.py b/evoque_dashboard/workflows/views.py new file mode 100644 index 0000000..ab57f58 --- /dev/null +++ b/evoque_dashboard/workflows/views.py @@ -0,0 +1,33 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from django.utils.translation import ugettext_lazy as _ + +from evoque_dashboard.api import evoque +from evoque_dashboard.workflows.tables import WorkflowsTable + +from horizon import exceptions +from horizon import tables + + +class IndexView(tables.DataTableView): + table_class = WorkflowsTable + template_name = 'ticket/workflows/index.html' + + def get_data(self): + try: + workflows = evoque.workflow_list(self.request) + except Exception: + workflows = [] + exceptions.handle(self.request, + _('Unable to retrieve workflows.')) + return workflows diff --git a/test-requirements.txt b/test-requirements.txt index 496da20..eb66e3f 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -5,6 +5,7 @@ hacking<0.11,>=0.10.0 # Testing Requirements http://tarballs.openstack.org/horizon/horizon-master.tar.gz#egg=horizon +http://tarballs.openstack.org/python-evoqueclient/python-evoqueclient-master.tar.gz#egg=python-evoqueclient coverage>=3.6 django-nose>=1.2