Introducing form overrides for label and tooltips

This commit is contained in:
Maxime Beauchemin 2015-12-09 15:19:43 -08:00
parent 9c0dd5bf3c
commit d476dd2b8a
3 changed files with 35 additions and 6 deletions

View File

@ -9,8 +9,8 @@
{% endblock %}
{% block tail_js %}
{{ super() }}
<script src="/static/panoramix.js"></script>
<script src="/static/lib/jquery-ui/jquery-ui.min.js"></script>
<script src="/static/lib/select2.sortable.js"></script>
{{ super() }}
{% endblock %}

View File

@ -36,10 +36,10 @@
<div>
{% set field = form.get_field(fieldname)%}
<div>
{{ field.label }}
{{ viz.get_form_override(fieldname, 'label') or field.label }}
{% if field.description %}
<i class="fa fa-info-circle" data-toggle="tooltip" data-placement="right"
title="{{ field.description }}"></i>
title="{{ viz.get_form_override(fieldname, 'description') or field.description }}"></i>
{% endif %}
{{ field(class_=form.field_css_classes(field.name)) }}
</div>
@ -51,10 +51,10 @@
<div class="col-xs-{{ (12 / fieldname|length) | int }}">
{% if name %}
{% set field = form.get_field(name)%}
{{ field.label }}
{{ viz.form_overrides.label or field.label }}
{% if field.description %}
<i class="fa fa-info-circle" data-toggle="tooltip" data-placement="right"
title="{{ field.description }}"></i>
title="{{ viz.get_form_override(fieldname, 'description') or field.description }}"></i>
{% endif %}
{{ field(class_=form.field_css_classes(field.name)) }}
{% endif %}

View File

@ -3,7 +3,7 @@ from datetime import datetime, timedelta
import json
import uuid
from flask import flash, request
from flask import flash, request, Markup
from markdown import markdown
from pandas.io.json import dumps
from werkzeug.datastructures import ImmutableMultiDict
@ -36,6 +36,7 @@ class BaseViz(object):
},)
js_files = []
css_files = []
form_overrides = {}
def __init__(self, datasource, form_data):
self.orig_form_data = form_data
@ -74,6 +75,16 @@ class BaseViz(object):
self.groupby = self.form_data.get('groupby') or []
self.reassignments()
def get_form_override(self, fieldname, attr):
if (
fieldname in self.form_overrides and
attr in self.form_overrides[fieldname]):
s = self.form_overrides[fieldname][attr]
if attr == 'label':
s = '<label for="{fieldname}">{s}</label>'.format(**locals())
s = Markup(s)
return s
def fieldsetizer(self):
"""
Makes form_fields support either a list approach or a fieldsets
@ -804,6 +815,24 @@ class SunburstViz(BaseViz):
'limit',
)
},)
form_overrides = {
'metric': {
'label': 'Primary Metric',
'description': (
"The primary metric is used to "
"define the arc segment sizes"),
},
'secondary_metric': {
'label': 'Secondary Metric',
'description': (
"This secondary metric is used to "
"define the color as a ratio against the primary metric"),
},
'groupby': {
'label': 'Hierarchy',
'description': "This defines the level of the hierarchy",
},
}
def get_df(self):
df = super(SunburstViz, self).get_df()