From f592aa1012073b136433d57ca022edae904e63a2 Mon Sep 17 00:00:00 2001 From: Patrick Leo Tardif Date: Fri, 13 Nov 2015 17:16:34 -0800 Subject: [PATCH] Add BetterBooleanField --- panoramix/forms.py | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/panoramix/forms.py b/panoramix/forms.py index c598ec046dcd6..9190f510e5fc8 100644 --- a/panoramix/forms.py +++ b/panoramix/forms.py @@ -2,12 +2,23 @@ Field, Form, SelectMultipleField, SelectField, TextField, TextAreaField, BooleanField, IntegerField, HiddenField) from wtforms import validators +from wtforms.widgets import HTMLString from copy import copy from panoramix import app from six import string_types config = app.config +# Fixes behavior of html forms omitting non checked +# (which doesn't distinguish False from NULL/missing ) +# If value is unchecked, this hidden fills in False value +class BetterBooleanField(BooleanField): + def __call__(self, **kwargs): + html = super(BetterBooleanField, self).__call__(**kwargs) + html += u'' + return HTMLString(html) + + class OmgWtForm(Form): field_order = tuple() css_classes = dict() @@ -160,28 +171,28 @@ def __init__(self, viz): "Font Size To", default="150", description="Font size for the biggest value in the list"), - 'show_brush': BooleanField( + 'show_brush': BetterBooleanField( "Range Selector", default=True, description="Whether to display the time range interactive selector"), - 'show_legend': BooleanField( + 'show_legend': BetterBooleanField( "Legend", default=True, description="Whether to display the legend (toggles)"), - 'rich_tooltip': BooleanField( + 'rich_tooltip': BetterBooleanField( "Rich Tooltip", default=True, description="The rich tooltip shows a list of all series for that point in time"), - 'y_axis_zero': BooleanField( + 'y_axis_zero': BetterBooleanField( "Y Axis Zero", default=False, description="Force the Y axis to start at 0 instead of the minimum value"), - 'y_log_scale': BooleanField( + 'y_log_scale': BetterBooleanField( "Y Log", default=False, description="Use a log scale for the Y axis"), - 'x_log_scale': BooleanField( + 'x_log_scale': BetterBooleanField( "X Log", default=False, description="Use a log scale for the X axis"), - 'donut': BooleanField( + 'donut': BetterBooleanField( "Donut", default=False, description="Do you want a donut or a pie?"), - 'contribution': BooleanField( + 'contribution': BetterBooleanField( "Contribution", default=False, description="Compute the contribution to the total"), 'num_period_compare': IntegerField(