From b7a6a23344d3c7fecf2d3f15d2e6d48ec92a0950 Mon Sep 17 00:00:00 2001 From: Kirill Zaitsev Date: Mon, 23 May 2016 17:27:41 +0300 Subject: [PATCH] Use template filter to convert list of packages in the template Before this patch _data_table.html checked string representation to check if the list is empty. This patch adds jsonify filter and moves actual jsonification into template, thus eliminating the need to compare string representation of lists. Change-Id: Iddf6ab7c8cff1d1dff98badbd117200e9d3b22e7 Closes-Bug: #1584802 --- muranodashboard/environments/tables.py | 4 +--- .../templates/services/_data_table.html | 11 +++------ muranodashboard/templatetags/jsonify.py | 23 +++++++++++++++++++ 3 files changed, 27 insertions(+), 11 deletions(-) create mode 100644 muranodashboard/templatetags/jsonify.py diff --git a/muranodashboard/environments/tables.py b/muranodashboard/environments/tables.py index 4971a9a99..bf1dd0cab 100644 --- a/muranodashboard/environments/tables.py +++ b/muranodashboard/environments/tables.py @@ -12,8 +12,6 @@ # License for the specific language governing permissions and limitations # under the License. -import json - from django.core.urlresolvers import reverse from django import http as django_http from django import shortcuts @@ -417,7 +415,7 @@ class ServicesTable(tables.DataTable): packages, self._more = pkg_api.package_list( self.request, filters={'type': 'Application', 'catalog': True}) - return json.dumps([package.to_dict() for package in packages]) + return [package.to_dict() for package in packages] def actions_allowed(self): status, version = _get_environment_status_and_version( diff --git a/muranodashboard/templates/services/_data_table.html b/muranodashboard/templates/services/_data_table.html index 5a0bceca3..53e836454 100644 --- a/muranodashboard/templates/services/_data_table.html +++ b/muranodashboard/templates/services/_data_table.html @@ -1,15 +1,10 @@ {% load i18n %} {% load custom_filters %} +{% load jsonify %} {% block table_caption %} {% with apps=table.get_apps_list %} - {% comment %} - Note(efedorova): We are comparing to the string, since get_apps_list - functions returns json.dumps, which is used in js later. - So to prevent extra transformations comparing to the string is used - to check for app absence. - {% endcomment %} - {% if apps != '[]' %} + {% if apps %}

{% trans "Application Components" %}

@@ -79,7 +74,7 @@ {% trans "There are no applications matching your criteria." %}