misc: use real Python types for datetime widget options
This commit is contained in:
parent
2da78fd12a
commit
46345d3c53
|
@ -22,8 +22,8 @@ from chrono.agendas.models import Event
|
|||
|
||||
|
||||
DATETIME_OPTIONS = {
|
||||
'weekStart': '1',
|
||||
'autoclose': 'true',
|
||||
'weekStart': 1,
|
||||
'autoclose': True,
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -61,47 +61,6 @@ BOOTSTRAP_INPUT_TEMPLATE = """
|
|||
CLEAR_BTN_TEMPLATE = """<span class="add-on"><i class="icon-remove"></i></span>"""
|
||||
|
||||
|
||||
quoted_options = set([
|
||||
'format',
|
||||
'startDate',
|
||||
'endDate',
|
||||
'startView',
|
||||
'minView',
|
||||
'maxView',
|
||||
'todayBtn',
|
||||
'language',
|
||||
'pickerPosition',
|
||||
'viewSelect',
|
||||
'initialDate',
|
||||
'weekStart',
|
||||
'minuteStep'
|
||||
'daysOfWeekDisabled',
|
||||
])
|
||||
|
||||
# to traslate boolean object to javascript
|
||||
quoted_bool_options = set([
|
||||
'autoclose',
|
||||
'todayHighlight',
|
||||
'showMeridian',
|
||||
'clearBtn',
|
||||
])
|
||||
|
||||
|
||||
def quote(key, value):
|
||||
"""Certain options support string values. We want clients to be able to pass Python strings in
|
||||
but we need them to be quoted in the output. Unfortunately some of those options also allow
|
||||
numbers so we type check the value before wrapping it in quotes.
|
||||
"""
|
||||
|
||||
if key in quoted_options and isinstance(value, string_types):
|
||||
return "'%s'" % value
|
||||
|
||||
if key in quoted_bool_options and isinstance(value, bool):
|
||||
return json.dumps(value)
|
||||
|
||||
return value
|
||||
|
||||
|
||||
class PickerWidgetMixin(object):
|
||||
|
||||
format_name = None
|
||||
|
@ -135,19 +94,17 @@ class PickerWidgetMixin(object):
|
|||
# Build javascript options out of python dictionary
|
||||
options_list = []
|
||||
for key, value in iter(self.options.items()):
|
||||
options_list.append("%s: %s" % (key, quote(key, value)))
|
||||
options_list.append("%s: %s" % (key, json.dumps(value)))
|
||||
|
||||
js_options = ",\n".join(options_list)
|
||||
|
||||
# Use provided id or generate hex to avoid collisions in document
|
||||
id = final_attrs.get('id', uuid.uuid4().hex)
|
||||
|
||||
clear_button = quote('clearBtn', self.options.get('clearBtn', 'true')) == 'true'
|
||||
|
||||
return mark_safe(BOOTSTRAP_INPUT_TEMPLATE % dict(
|
||||
id=id,
|
||||
rendered_widget=rendered_widget,
|
||||
clear_button=CLEAR_BTN_TEMPLATE if clear_button else "",
|
||||
clear_button=CLEAR_BTN_TEMPLATE if self.options.get('clearBtn') else '',
|
||||
glyphicon=self.glyphicon,
|
||||
options=js_options
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue