From a8af4b2972b452031f2349bea94868be40f1792b Mon Sep 17 00:00:00 2001 From: Zhenguo Niu Date: Fri, 5 May 2017 11:20:34 +0800 Subject: [PATCH] Add Servers table Change-Id: Ib8cbe11a86efd5c38678aa2cb56a106f601ce5a8 --- mogan_ui/api/{client.py => mogan.py} | 0 mogan_ui/api/rest_api.py | 4 +- mogan_ui/content/servers/tables.py | 34 +++++++++++++++++ .../servers/templates/servers/index.html | 7 ++++ mogan_ui/content/servers/urls.py | 6 +-- mogan_ui/content/servers/views.py | 37 +++++++++++++++++++ 6 files changed, 82 insertions(+), 6 deletions(-) rename mogan_ui/api/{client.py => mogan.py} (100%) create mode 100644 mogan_ui/content/servers/tables.py create mode 100644 mogan_ui/content/servers/templates/servers/index.html create mode 100644 mogan_ui/content/servers/views.py diff --git a/mogan_ui/api/client.py b/mogan_ui/api/mogan.py similarity index 100% rename from mogan_ui/api/client.py rename to mogan_ui/api/mogan.py diff --git a/mogan_ui/api/rest_api.py b/mogan_ui/api/rest_api.py index b28a1ff..7bffb20 100644 --- a/mogan_ui/api/rest_api.py +++ b/mogan_ui/api/rest_api.py @@ -12,7 +12,7 @@ from django.views import generic -from mogan_ui.api import client +from mogan_ui.api import mogan from openstack_dashboard.api.rest import urls from openstack_dashboard.api.rest import utils as rest_utils @@ -30,5 +30,5 @@ class Servers(generic.View): :param request: HTTP request. :return: servers. """ - servers = client.server_list(request) + servers = mogan.server_list(request) return {'servers': [s.to_dict() for s in servers]} diff --git a/mogan_ui/content/servers/tables.py b/mogan_ui/content/servers/tables.py new file mode 100644 index 0000000..fa1491c --- /dev/null +++ b/mogan_ui/content/servers/tables.py @@ -0,0 +1,34 @@ +# Copyright 2017 Huawei Technologies Co.,LTD. +# All Rights Reserved. +# +# 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 + + +class ServersTable(tables.DataTable): + + name = tables.WrappingColumn( + "name", + verbose_name=_("Name")) + status = tables.Column("status", + verbose_name=_("Status")) + + def get_object_id(self, obj): + return obj.uuid + + class Meta(object): + name = "servers" + verbose_name = _("Servers") diff --git a/mogan_ui/content/servers/templates/servers/index.html b/mogan_ui/content/servers/templates/servers/index.html new file mode 100644 index 0000000..f4f006f --- /dev/null +++ b/mogan_ui/content/servers/templates/servers/index.html @@ -0,0 +1,7 @@ +{% extends 'base.html' %} +{% load i18n %} +{% block title %}{% trans "Servers" %}{% endblock %} + +{% block main %} + {{ table.render }} +{% endblock %} diff --git a/mogan_ui/content/servers/urls.py b/mogan_ui/content/servers/urls.py index 30792d1..2cd0c21 100644 --- a/mogan_ui/content/servers/urls.py +++ b/mogan_ui/content/servers/urls.py @@ -14,10 +14,8 @@ # limitations under the License. from django.conf.urls import url -from django.utils.translation import ugettext_lazy as _ -from horizon.browsers import views +from mogan_ui.content.servers import views -title = _("Servers") urlpatterns = [ - url('', views.AngularIndexView.as_view(title=title), name='index'), + url(r'^$', views.IndexView.as_view(), name='index'), ] diff --git a/mogan_ui/content/servers/views.py b/mogan_ui/content/servers/views.py new file mode 100644 index 0000000..6a6c784 --- /dev/null +++ b/mogan_ui/content/servers/views.py @@ -0,0 +1,37 @@ +# Copyright 2017 Huawei Technologies Co.,LTD. +# All Rights Reserved. + +# 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 mogan_ui.api import mogan +from mogan_ui.content.servers.tables import ServersTable + +from horizon import exceptions +from horizon import tables + + +class IndexView(tables.DataTableView): + table_class = ServersTable + template_name = 'project/servers/index.html' + page_title = _("Servers") + + def get_data(self): + try: + servers = mogan.server_list(self.request) + except Exception: + servers = [] + msg = _('Unable to retrieve servers.') + exceptions.handle(self.request, msg) + return servers