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
This commit is contained in:
parent
7a334ac144
commit
b7a6a23344
|
@ -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(
|
||||
|
|
|
@ -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 %}
|
||||
<div class="col-xs-5">
|
||||
<h3 class="table_title extra_title table_title">
|
||||
{% trans "Application Components" %}</h3>
|
||||
|
@ -79,7 +74,7 @@
|
|||
{% trans "There are no applications matching your criteria." %}</p>
|
||||
<div id="apps_carousel" class="carousel">
|
||||
<input type="hidden" id="apps_carousel_contents"
|
||||
value="{{ apps }}">
|
||||
value="{{ apps|jsonify }}">
|
||||
|
||||
<div class="carousel-inner"></div>
|
||||
<a class="left carousel-control" ng-non-bindable href="#apps_carousel"
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
# Copyright (c) 2016 Mirantis, Inc.
|
||||
#
|
||||
# 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 import template
|
||||
import json
|
||||
|
||||
register = template.Library()
|
||||
|
||||
|
||||
@register.filter(name='jsonify')
|
||||
def jsonify(value):
|
||||
return json.dumps(value)
|
Loading…
Reference in New Issue