From e98f2429fa32729b6bf7be22c03d0b9baa9ebb49 Mon Sep 17 00:00:00 2001 From: Sam Betts Date: Wed, 12 Nov 2014 14:38:48 +0000 Subject: [PATCH] Remove duplicated headings from horizon tables Many panels in horizon only contain a single table, in these cases the tables often have the same name as the panel, leading to duplicated headings, e.g. Instances (panel heading) then Instances (table heading). This patch adds an attribute the table to hide or show the title, since the majority of panels have this duplication this flag is set to hide the heading by default allowing a developer to re-enable it for specific cases. Tabbed panels also often lead to duplicated titles between the panel heading and the tabs themselves, that is not fixed, however how this patch reduces the duplication in the case of Volumes (panel name), Volumes (tab name) and Volumes (table name), by hiding the table heading. Change-Id: I65efa53cc881417288e5c5b29bfa7d539e97c7dd Closes-Bug: 1379044 --- horizon/tables/base.py | 9 ++++++++- horizon/templates/horizon/common/_data_table.html | 4 +++- horizon/test/tests/tables.py | 7 +++++++ .../dashboards/admin/aggregates/tables.py | 2 ++ .../dashboards/admin/volumes/volume_types/tables.py | 2 ++ openstack_dashboard/usage/tables.py | 2 ++ 6 files changed, 24 insertions(+), 2 deletions(-) diff --git a/horizon/tables/base.py b/horizon/tables/base.py index bb029f8948..2c2f08fb5c 100644 --- a/horizon/tables/base.py +++ b/horizon/tables/base.py @@ -943,6 +943,11 @@ class DataTableOptions(object): Boolean to control whether or not to show the table's footer. Default: ``True``. + .. attribute:: hidden_title + + Boolean to control whether or not to show the table's title. + Default: ``True``. + .. attribute:: permissions A list of permission names which this table requires in order to be @@ -968,6 +973,7 @@ class DataTableOptions(object): self.pagination_param = getattr(options, 'pagination_param', 'marker') self.browser_table = getattr(options, 'browser_table', None) self.footer = getattr(options, 'footer', True) + self.hidden_title = getattr(options, 'hidden_title', True) self.no_data_message = getattr(options, "no_data_message", _("No items to display.")) @@ -1253,7 +1259,8 @@ class DataTable(object): def render(self): """Renders the table using the template from the table options.""" table_template = template.loader.get_template(self._meta.template) - extra_context = {self._meta.context_var_name: self} + extra_context = {self._meta.context_var_name: self, + 'hidden_title': self._meta.hidden_title} context = template.RequestContext(self.request, extra_context) return table_template.render(context) diff --git a/horizon/templates/horizon/common/_data_table.html b/horizon/templates/horizon/common/_data_table.html index c7d2cf0a89..75630fa7ee 100644 --- a/horizon/templates/horizon/common/_data_table.html +++ b/horizon/templates/horizon/common/_data_table.html @@ -9,7 +9,9 @@ {% block table_caption %} -

{{ table }}

+ {% if not hidden_title %} +

{{ table }}

+ {% endif %} {{ table.render_table_actions }} diff --git a/horizon/test/tests/tables.py b/horizon/test/tests/tables.py index 93712c4609..7ba4517b17 100644 --- a/horizon/test/tests/tables.py +++ b/horizon/test/tests/tables.py @@ -581,12 +581,19 @@ class DataTableTests(test.TestCase): update_string = "action=row_update&table=my_table&obj_id=" self.assertContains(resp, update_string, 3) self.assertContains(resp, "data-update-interval", 3) + # Verify no table heading + self.assertNotContains(resp, "

' '<strong>evil</strong>', 1) + # Hidden Title = False shows the table title + self.table._meta.hidden_title = False + resp = http.HttpResponse(self.table.render()) + self.assertContains(resp, "