summaryrefslogtreecommitdiff
path: root/horizon/templatetags
diff options
context:
space:
mode:
authorDiana Whitten <hurgleburgler@gmail.com>2015-11-13 13:42:45 -0700
committerDiana Whitten <hurgleburgler@gmail.com>2015-12-18 12:28:25 -0700
commitf5f371655e6b406a2cb48ca1a9373ea894519bbc (patch)
tree79a9e43a06ff28dfa507bfd2e867761eaed36c1b /horizon/templatetags
parent98cb37d7cee56ab61b5ec1f47dbfdcd89a5daf84 (diff)
downloadhorizon-f5f371655e6b406a2cb48ca1a9373ea894519bbc.tar.gz
Barcharts now inherit from a Bootstrap Theme
Barcharts were using a complex D3 mechanism to draw very very simple markup that can be achieved using a simple Bootstrap Stacked Progress Bar. A templatetag was added to aid in markup reuse. Also, a 'minifyspace' template helper was also added that enables us to make templates that have excessive attributes to be more readable, while not affecting the rendered HTML on the page. By moving the logic to simple markup, the rendering of the barcharts are now immediate on the page, instead of requiring Horizon Init functions to run and draw. This immediate render removes the first animation on the Quota bars, but it retains animations driven by user interaction with the forms. It was hoped that horizon.d3barchart.js could be completely removed, but it is currently being used by horizon.d3linechart.js. This will be addressed soon, but was outside of the scope of this patch. Much of the markup on the Quota pages was cleaned up and made simpler to use existing style as well as replacing improper usage of <strong> Summary of Improvements: * Immediate Render time for Bar Charts * Bar Charts now Inherit from theme, and use progress bar styles * 'minifyspace' was added to increase readability to templates * bs_progress_bar templatetag was added to facilitate code reuse * Markup for Quota Bar pages refactored Partially-Implements: blueprint horizon-theme-css-reorg Partially-Implements: blueprint bootstrap-html-standards Change-Id: I16a1e3955d3a4fded0f2ea6a87f5e7c2f630185d
Diffstat (limited to 'horizon/templatetags')
-rw-r--r--horizon/templatetags/bootstrap.py58
-rw-r--r--horizon/templatetags/horizon.py5
2 files changed, 59 insertions, 4 deletions
diff --git a/horizon/templatetags/bootstrap.py b/horizon/templatetags/bootstrap.py
new file mode 100644
index 000000000..4c9005949
--- /dev/null
+++ b/horizon/templatetags/bootstrap.py
@@ -0,0 +1,58 @@
+# Copyright 2015 Hewlett Packard Enterprise Software, LLC
+# All Rights Reserved.
+#
+# 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 __future__ import absolute_import
+
+from django import template
+
+
+register = template.Library()
+
+
+@register.inclusion_tag('bootstrap/progress_bar.html')
+def bs_progress_bar(*args, **kwargs):
+ """A Standard Bootstrap Progress Bar.
+ http://getbootstrap.com/components/#progress
+
+ param args (Array of Numbers: 0-100): Percent of Progress Bars
+ param context (String): Adds 'progress-bar-{context} to the class attribute
+ param contexts (Array of Strings): Cycles through contexts for stacked bars
+ param text (Boolean): True: shows value within the bar, False: uses sr span
+ param striped (Boolean): Adds 'progress-bar-striped' to the class attribute
+ param animated (Boolean): Adds 'active' to the class attribute if striped
+ param min_val (0): Used for the aria-min value
+ param max_val (0): Used for the aria-max value
+ """
+
+ bars = []
+ contexts = kwargs.get(
+ 'contexts',
+ ['', 'success', 'info', 'warning', 'danger']
+ )
+
+ for ndx, arg in enumerate(args):
+ bars.append(
+ dict(percent=arg,
+ context=kwargs.get('context', contexts[ndx % len(contexts)]))
+ )
+
+ return {
+ 'bars': bars,
+ 'text': kwargs.pop('text', False),
+ 'striped': kwargs.pop('striped', False),
+ 'animated': kwargs.pop('animated', False),
+ 'min_val': kwargs.pop('min_val', 0),
+ 'max_val': kwargs.pop('max_val', 100),
+ }
diff --git a/horizon/templatetags/horizon.py b/horizon/templatetags/horizon.py
index bca67bd45..d2d99b1c3 100644
--- a/horizon/templatetags/horizon.py
+++ b/horizon/templatetags/horizon.py
@@ -27,6 +27,7 @@ from django.utils.translation import ugettext_lazy as _
from horizon.base import Horizon # noqa
from horizon import conf
+
register = template.Library()
@@ -214,9 +215,7 @@ def datepicker_locale():
def minifyspace(parser, token):
"""Removes whitespace including tab and newline characters. Do not use this
if you are using a <pre> tag
-
Example usage::
-
{% minifyspace %}
<p>
<a title="foo"
@@ -225,9 +224,7 @@ def minifyspace(parser, token):
</a>
</p>
{% endminifyspace %}
-
This example would return this HTML::
-
<p><a title="foo" href="foo/">Foo</a></p>
"""
nodelist = parser.parse(('endminifyspace',))