From f14da6cb4f936cfe3c7ffb9df6f60e62b16fe32d Mon Sep 17 00:00:00 2001 From: Ana Krivokapic Date: Wed, 29 Oct 2014 17:04:02 +0100 Subject: [PATCH] Add counts to index pages Add counts to index pages for Nodes, Images and Roles. Change-Id: I8b52fe05fb9fc3dac9675cdddf8cc9750aa55ee8 --- .../images/templates/images/index.html | 2 +- tuskar_ui/infrastructure/images/views.py | 5 +++- .../nodes/templates/nodes/index.html | 2 +- tuskar_ui/infrastructure/nodes/tests.py | 4 ++-- tuskar_ui/infrastructure/nodes/views.py | 8 ++++++- .../roles/templates/roles/index.html | 2 +- tuskar_ui/infrastructure/roles/views.py | 5 +++- .../_items_count_domain_page_header.html | 2 +- tuskar_ui/infrastructure/views.py | 23 +++++++++++++++++++ 9 files changed, 44 insertions(+), 9 deletions(-) create mode 100644 tuskar_ui/infrastructure/views.py diff --git a/tuskar_ui/infrastructure/images/templates/images/index.html b/tuskar_ui/infrastructure/images/templates/images/index.html index 94e79802d..a6ca58012 100644 --- a/tuskar_ui/infrastructure/images/templates/images/index.html +++ b/tuskar_ui/infrastructure/images/templates/images/index.html @@ -3,7 +3,7 @@ {% block title %}{% trans 'Provisioning Images' %}{% endblock %} {% block page_header %} - {% include 'horizon/common/_page_header.html' with title=_('Provisioning Images') %} + {% include 'horizon/common/_items_count_domain_page_header.html' with title=_('Provisioning Images') %} {% endblock page_header %} {% block main %} diff --git a/tuskar_ui/infrastructure/images/views.py b/tuskar_ui/infrastructure/images/views.py index e530031e4..56a609864 100644 --- a/tuskar_ui/infrastructure/images/views.py +++ b/tuskar_ui/infrastructure/images/views.py @@ -25,15 +25,18 @@ from openstack_dashboard.dashboards.project.images.images import views from tuskar_ui import api as tuskar_api from tuskar_ui.infrastructure.images import forms from tuskar_ui.infrastructure.images import tables +import tuskar_ui.infrastructure.views as infrastructure_views from tuskar_ui.utils import utils LOG = logging.getLogger(__name__) -class IndexView(horizon_tables.DataTableView): +class IndexView(infrastructure_views.ItemCountMixin, + horizon_tables.DataTableView): table_class = tables.ImagesTable template_name = "infrastructure/images/index.html" + @memoized.memoized_method def get_data(self): images = [] filters = self.get_filters() diff --git a/tuskar_ui/infrastructure/nodes/templates/nodes/index.html b/tuskar_ui/infrastructure/nodes/templates/nodes/index.html index 543083d65..302d44189 100644 --- a/tuskar_ui/infrastructure/nodes/templates/nodes/index.html +++ b/tuskar_ui/infrastructure/nodes/templates/nodes/index.html @@ -4,7 +4,7 @@ {% block title %}{% trans 'Nodes' %}{% endblock %} {% block page_header %} - {% include 'horizon/common/_items_count_domain_page_header.html' with title=_('Nodes') items_count=nodes_count %} + {% include 'horizon/common/_items_count_domain_page_header.html' with title=_('Nodes') %} {% endblock page_header %} {% block main %} diff --git a/tuskar_ui/infrastructure/nodes/tests.py b/tuskar_ui/infrastructure/nodes/tests.py index 0ee977dc4..aa293f022 100644 --- a/tuskar_ui/infrastructure/nodes/tests.py +++ b/tuskar_ui/infrastructure/nodes/tests.py @@ -54,7 +54,7 @@ class NodesTests(test.BaseAdminViewTests, helpers.APITestCase): 'list.return_value': [], }) as mock: res = self.client.get(INDEX_URL) - self.assertEqual(mock.list.call_count, 5) + self.assertEqual(mock.list.call_count, 6) self.assertTemplateUsed( res, 'infrastructure/nodes/index.html') @@ -75,7 +75,7 @@ class NodesTests(test.BaseAdminViewTests, helpers.APITestCase): 'list.return_value': nodes, }) as Node: res = self.client.get(INDEX_URL + '?tab=nodes__' + tab_name) - self.assertEqual(Node.list.call_count, 5) + self.assertEqual(Node.list.call_count, 6) self.assertTemplateUsed( res, 'infrastructure/nodes/index.html') diff --git a/tuskar_ui/infrastructure/nodes/views.py b/tuskar_ui/infrastructure/nodes/views.py index 8267e5d3a..53e1195aa 100644 --- a/tuskar_ui/infrastructure/nodes/views.py +++ b/tuskar_ui/infrastructure/nodes/views.py @@ -28,10 +28,12 @@ from tuskar_ui import api from tuskar_ui.infrastructure.nodes import forms from tuskar_ui.infrastructure.nodes import tables from tuskar_ui.infrastructure.nodes import tabs +import tuskar_ui.infrastructure.views as infrastructure_views from tuskar_ui.utils import metering as metering_utils -class IndexView(horizon_tabs.TabbedTableView): +class IndexView(infrastructure_views.ItemCountMixin, + horizon_tabs.TabbedTableView): tab_group_class = tabs.NodeTabs template_name = 'infrastructure/nodes/index.html' @@ -54,6 +56,10 @@ class IndexView(horizon_tabs.TabbedTableView): context['header_actions'].append(upload_action) return context + @memoized.memoized_method + def get_data(self): + return api.node.Node.list(self.request) + class RegisterView(horizon_forms.ModalFormView): form_class = forms.RegisterNodeFormset diff --git a/tuskar_ui/infrastructure/roles/templates/roles/index.html b/tuskar_ui/infrastructure/roles/templates/roles/index.html index a43f14ff9..879cc695b 100644 --- a/tuskar_ui/infrastructure/roles/templates/roles/index.html +++ b/tuskar_ui/infrastructure/roles/templates/roles/index.html @@ -3,7 +3,7 @@ {% block title %}{% trans 'Deployment Roles' %}{% endblock %} {% block page_header %} - {% include 'horizon/common/_page_header.html' with title=_('Deployment Roles') %} + {% include 'horizon/common/_items_count_domain_page_header.html' with title=_('Deployment Roles') %} {% endblock page_header %} {% block main %} diff --git a/tuskar_ui/infrastructure/roles/views.py b/tuskar_ui/infrastructure/roles/views.py index 9f11cc41d..a19aa72d9 100644 --- a/tuskar_ui/infrastructure/roles/views.py +++ b/tuskar_ui/infrastructure/roles/views.py @@ -28,6 +28,7 @@ from openstack_dashboard.api import base as api_base from tuskar_ui import api from tuskar_ui.infrastructure.roles import tables from tuskar_ui.infrastructure.roles import workflows as role_workflows +import tuskar_ui.infrastructure.views as infrastructure_views from tuskar_ui.utils import metering as metering_utils @@ -50,10 +51,12 @@ class StackMixin(object): return api.heat.Stack.get_by_plan(self.request, plan) -class IndexView(horizon_tables.DataTableView): +class IndexView(infrastructure_views.ItemCountMixin, + horizon_tables.DataTableView): table_class = tables.RolesTable template_name = "infrastructure/roles/index.html" + @utils.memoized.memoized def get_data(self): roles = api.tuskar.Role.list(self.request) plan = api.tuskar.Plan.get_the_plan(self.request) diff --git a/tuskar_ui/infrastructure/templates/horizon/common/_items_count_domain_page_header.html b/tuskar_ui/infrastructure/templates/horizon/common/_items_count_domain_page_header.html index 77bcca01d..dafe4007b 100644 --- a/tuskar_ui/infrastructure/templates/horizon/common/_items_count_domain_page_header.html +++ b/tuskar_ui/infrastructure/templates/horizon/common/_items_count_domain_page_header.html @@ -7,7 +7,7 @@ {{ request.session.domain_context_name }}: {% endif %} {{ title }} - {% if items_count %} + {% if items_count or items_count == 0%} {{ items_count }} diff --git a/tuskar_ui/infrastructure/views.py b/tuskar_ui/infrastructure/views.py new file mode 100644 index 000000000..d432a3c4b --- /dev/null +++ b/tuskar_ui/infrastructure/views.py @@ -0,0 +1,23 @@ +# -*- coding: utf8 -*- +# +# 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. + + +class ItemCountMixin(object): + def get_items_count(self): + return len(self.get_data()) + + def get_context_data(self, **kwargs): + context = super(ItemCountMixin, self).get_context_data(**kwargs) + context['items_count'] = self.get_items_count() + return context