From 9d7f30eef8cbb2c59fdc067cc9216ea937f1384b Mon Sep 17 00:00:00 2001 From: zhurong Date: Thu, 25 Aug 2016 23:12:00 +0800 Subject: [PATCH] Using WrappingColumn to prevent long names breaking table layouts Now WrappingColumn was introduced in Horizon, So we can using this to prevent long names breaking table layouts. Closes-Bug: #1618961 Change-Id: Ic5db239752a147c364823ed9fcd192181098f976 --- muranodashboard/categories/tables.py | 3 ++- muranodashboard/common/utils.py | 7 +++++++ muranodashboard/environments/tables.py | 24 ++++++++++++------------ muranodashboard/images/tables.py | 7 ++++--- muranodashboard/packages/tables.py | 8 +++++--- 5 files changed, 30 insertions(+), 19 deletions(-) diff --git a/muranodashboard/categories/tables.py b/muranodashboard/categories/tables.py index e39dcf268..d2f727a5c 100644 --- a/muranodashboard/categories/tables.py +++ b/muranodashboard/categories/tables.py @@ -22,6 +22,7 @@ from muranoclient.common import exceptions as exc from oslo_log import log as logging from muranodashboard import api +from muranodashboard.common import utils as md_utils LOG = logging.getLogger(__name__) @@ -71,7 +72,7 @@ class DeleteCategory(tables.DeleteAction): class CategoriesTable(tables.DataTable): - name = tables.Column('name', verbose_name=_('Category Name')) + name = md_utils.Column('name', verbose_name=_('Category Name')) use_artifacts = getattr(settings, 'MURANO_USE_GLARE', False) if not use_artifacts: package_count = tables.Column('package_count', diff --git a/muranodashboard/common/utils.py b/muranodashboard/common/utils.py index dbf23f677..9d0343349 100644 --- a/muranodashboard/common/utils.py +++ b/muranodashboard/common/utils.py @@ -23,6 +23,13 @@ from muranodashboard.dynamic_ui import yaql_expression import six import yaql +# WrappingColumn is only available in N-horizon +# This make murano-dashboard compatible with Mitaka-horizon +try: + from horizon.tables import WrappingColumn as Column +except ImportError: + from horizon.tables import Column as Column # noqa + def parse_api_error(api_error_html): error_html = bs4.BeautifulSoup(api_error_html) diff --git a/muranodashboard/environments/tables.py b/muranodashboard/environments/tables.py index 434782c66..b25e4f554 100644 --- a/muranodashboard/environments/tables.py +++ b/muranodashboard/environments/tables.py @@ -30,11 +30,11 @@ from oslo_log import log as logging from muranodashboard import api as api_utils from muranodashboard.api import packages as pkg_api from muranodashboard.catalog import views as catalog_views +from muranodashboard.common import utils as md_utils from muranodashboard.environments import api from muranodashboard.environments import consts from muranodashboard.packages import consts as pkg_consts - LOG = logging.getLogger(__name__) @@ -426,12 +426,12 @@ class UpdateName(tables.UpdateAction): class EnvironmentsTable(tables.DataTable): - name = tables.Column('name', - link='horizon:murano:environments:services', - verbose_name=_('Name'), - form_field=forms.CharField(required=False), - update_action=UpdateName, - truncate=40) + name = md_utils.Column( + 'name', + link='horizon:murano:environments:services', + verbose_name=_('Name'), + form_field=forms.CharField(required=False), + update_action=UpdateName) status = tables.Column('status', verbose_name=_('Status'), @@ -462,9 +462,10 @@ def get_service_type(datum): class ServicesTable(tables.DataTable): - name = tables.Column('name', - verbose_name=_('Name'), - link=get_service_details_link) + name = md_utils.Column( + 'name', + verbose_name=_('Name'), + link=get_service_details_link) _type = tables.Column(get_service_type, verbose_name=_('Type')) @@ -587,8 +588,7 @@ class DeploymentsTable(tables.DataTable): class EnvConfigTable(tables.DataTable): - name = tables.Column('name', - verbose_name=_('Name')) + name = md_utils.Column('name', verbose_name=_('Name')) _type = tables.Column( lambda datum: get_service_type(datum) or 'Unknown', verbose_name=_('Type')) diff --git a/muranodashboard/images/tables.py b/muranodashboard/images/tables.py index 76f304ea9..c7373893f 100644 --- a/muranodashboard/images/tables.py +++ b/muranodashboard/images/tables.py @@ -19,6 +19,8 @@ from horizon import exceptions from horizon import tables from openstack_dashboard.api import glance +from muranodashboard.common import utils as md_utils + class MarkImage(tables.LinkAction): name = "mark_image" @@ -70,9 +72,8 @@ class MarkedImagesTable(tables.DataTable): ) type = tables.Column(lambda obj: getattr(obj, 'type', None), verbose_name=_('Type')) - title = tables.Column(lambda obj: getattr(obj, 'title', None), - verbose_name=_('Title'), - truncate=40) + title = md_utils.Column(lambda obj: getattr(obj, 'title', None), + verbose_name=_('Title')) class Meta(object): name = 'marked_images' diff --git a/muranodashboard/packages/tables.py b/muranodashboard/packages/tables.py index fddc39eac..98f39d59b 100644 --- a/muranodashboard/packages/tables.py +++ b/muranodashboard/packages/tables.py @@ -25,6 +25,7 @@ from oslo_log import log as logging from muranoclient.common import exceptions as exc from muranodashboard import api +from muranodashboard.common import utils as md_utils LOG = logging.getLogger(__name__) @@ -214,9 +215,10 @@ class ModifyPackage(tables.LinkAction): class PackageDefinitionsTable(tables.DataTable): - name = tables.Column('name', - link="horizon:murano:packages:detail", - verbose_name=_('Package Name')) + name = md_utils.Column( + 'name', + link="horizon:murano:packages:detail", + verbose_name=_('Package Name')) tenant_name = tables.Column('tenant_name', verbose_name=_('Tenant Name')) enabled = tables.Column('enabled', verbose_name=_('Active')) is_public = tables.Column('is_public', verbose_name=_('Public'))