Merge "Use template filter to convert list of packages in the template"

This commit is contained in:
Jenkins 2016-06-21 05:36:47 +00:00 committed by Gerrit Code Review
commit d8d76e4489
3 changed files with 27 additions and 11 deletions

View File

@ -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
@ -493,7 +491,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(

View File

@ -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&nbsp;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"

View File

@ -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)