Change project details view in a tab view.
Change the existing project details view into a tabbed view with currently just one tab (overview tab) which presents general informations of the project. This is done to be able to add other tabs to the project details view. Change-Id: I207d0671e41c478c258226fd21f83b6e9fd38ea4 Partial-Bug: #1785263
This commit is contained in:
parent
a4443f4be7
commit
c42aacb27b
|
@ -0,0 +1,42 @@
|
|||
# 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 django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from horizon import tabs
|
||||
|
||||
from openstack_dashboard import api
|
||||
|
||||
|
||||
class OverviewTab(tabs.Tab):
|
||||
"""Overview of the project. """
|
||||
name = _("Overview")
|
||||
slug = "overview"
|
||||
template_name = 'identity/projects/_detail_overview.html'
|
||||
|
||||
def get_context_data(self, request):
|
||||
project = self.tab_group.kwargs['project']
|
||||
context = {"project": project}
|
||||
|
||||
if api.keystone.VERSIONS.active >= 3:
|
||||
extra_info = getattr(settings, 'PROJECT_TABLE_EXTRA_INFO', {})
|
||||
context['extras'] = dict(
|
||||
(display_key, getattr(project, key, ''))
|
||||
for key, display_key in extra_info.items())
|
||||
|
||||
return context
|
||||
|
||||
|
||||
class ProjectDetailTabs(tabs.DetailTabsGroup):
|
||||
slug = "project_details"
|
||||
tabs = (OverviewTab,)
|
|
@ -25,6 +25,7 @@ import mock
|
|||
from horizon.workflows import views
|
||||
|
||||
from openstack_dashboard import api
|
||||
from openstack_dashboard.dashboards.identity.projects import tabs
|
||||
from openstack_dashboard.dashboards.identity.projects import workflows
|
||||
from openstack_dashboard.test import helpers as test
|
||||
from openstack_dashboard import usage
|
||||
|
@ -1295,7 +1296,9 @@ class DetailProjectViewTests(test.BaseAdminViewTests):
|
|||
|
||||
res = self.client.get(PROJECT_DETAIL_URL, args=[project.id])
|
||||
|
||||
self.assertTemplateUsed(res, 'identity/projects/detail.html')
|
||||
# The first tab is overview, it is the one loaded without query param
|
||||
# in the url.
|
||||
self.assertTemplateUsed(res, 'identity/projects/_detail_overview.html')
|
||||
self.assertEqual(res.context['project'].name, project.name)
|
||||
self.assertEqual(res.context['project'].id, project.id)
|
||||
|
||||
|
@ -1316,6 +1319,37 @@ class DetailProjectViewTests(test.BaseAdminViewTests):
|
|||
self.mock_tenant_get.assert_called_once_with(test.IsHttpRequest(),
|
||||
self.tenant.id)
|
||||
|
||||
@test.create_mocks({api.keystone: ('tenant_get',),
|
||||
quotas: ('enabled_quotas',)})
|
||||
def test_detail_view_overview_tab(self):
|
||||
"""Test the overview tab of the detail view .
|
||||
|
||||
Test the overview tab using directly the url targeting the tab.
|
||||
"""
|
||||
project = self.tenants.first()
|
||||
|
||||
self.mock_tenant_get.return_value = project
|
||||
self.mock_enabled_quotas.return_value = ('instances',)
|
||||
|
||||
# Url of the overview tab of the detail view
|
||||
url = PROJECT_DETAIL_URL % [project.id]
|
||||
detail_view = tabs.ProjectDetailTabs(self.request, project=project)
|
||||
overview_tab_link = "?%s=%s" % (
|
||||
detail_view.param_name,
|
||||
detail_view.get_tab("overview").get_id()
|
||||
)
|
||||
url += overview_tab_link
|
||||
|
||||
res = self.client.get(url)
|
||||
|
||||
self.assertTemplateUsed(res, 'identity/projects/_detail_overview.html')
|
||||
self.assertEqual(res.context['project'].name, project.name)
|
||||
self.assertEqual(res.context['project'].id, project.id)
|
||||
|
||||
self.mock_tenant_get.assert_called_once_with(test.IsHttpRequest(),
|
||||
self.tenant.id)
|
||||
self.mock_enabled_quotas.assert_called_once_with(test.IsHttpRequest())
|
||||
|
||||
|
||||
@tag('selenium')
|
||||
class SeleniumTests(test.SeleniumAdminTestCase, test.TestCase):
|
||||
|
|
|
@ -23,8 +23,8 @@ from django.utils.translation import ugettext_lazy as _
|
|||
from horizon import exceptions
|
||||
from horizon import messages
|
||||
from horizon import tables
|
||||
from horizon import tabs
|
||||
from horizon.utils import memoized
|
||||
from horizon import views
|
||||
from horizon import workflows
|
||||
|
||||
from openstack_dashboard import api
|
||||
|
@ -35,6 +35,8 @@ from openstack_dashboard.usage import quotas
|
|||
|
||||
from openstack_dashboard.dashboards.identity.projects \
|
||||
import tables as project_tables
|
||||
from openstack_dashboard.dashboards.identity.projects \
|
||||
import tabs as project_tabs
|
||||
from openstack_dashboard.dashboards.identity.projects \
|
||||
import workflows as project_workflows
|
||||
from openstack_dashboard.dashboards.project.overview \
|
||||
|
@ -231,8 +233,9 @@ class UpdateQuotasView(workflows.WorkflowView):
|
|||
return initial
|
||||
|
||||
|
||||
class DetailProjectView(views.HorizonTemplateView):
|
||||
template_name = 'identity/projects/detail.html'
|
||||
class DetailProjectView(tabs.TabView):
|
||||
tab_group_class = project_tabs.ProjectDetailTabs
|
||||
template_name = 'horizon/common/_detail.html'
|
||||
page_title = "{{ project.name }}"
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
|
@ -243,11 +246,6 @@ class DetailProjectView(views.HorizonTemplateView):
|
|||
context["url"] = reverse(INDEX_URL)
|
||||
context["actions"] = table.render_row_actions(project)
|
||||
|
||||
if keystone.VERSIONS.active >= 3:
|
||||
extra_info = getattr(settings, 'PROJECT_TABLE_EXTRA_INFO', {})
|
||||
context['extras'] = dict(
|
||||
(display_key, getattr(project, key, ''))
|
||||
for key, display_key in extra_info.items())
|
||||
return context
|
||||
|
||||
@memoized.memoized_method
|
||||
|
@ -260,3 +258,7 @@ class DetailProjectView(views.HorizonTemplateView):
|
|||
_('Unable to retrieve project details.'),
|
||||
redirect=reverse(INDEX_URL))
|
||||
return project
|
||||
|
||||
def get_tabs(self, request, *args, **kwargs):
|
||||
project = self.get_data()
|
||||
return self.tab_group_class(request, project=project, **kwargs)
|
||||
|
|
Loading…
Reference in New Issue