@@ -56,6 +56,21 @@ def conv_datetime_format_js2py(cls, format):
56
56
for js , py in cls .format_map :
57
57
format = format .replace (js , py )
58
58
return format
59
+
60
+ html_template = '''
61
+ <div%(div_attrs)s>
62
+ <input%(input_attrs)s/>
63
+ <span class="input-group-addon">
64
+ <span%(icon_attrs)s></span>
65
+ </span>
66
+ </div>'''
67
+
68
+ js_template = '''
69
+ <script>
70
+ $(function() {
71
+ $("#%(picker_id)s").datetimepicker(%(options)s);
72
+ });
73
+ </script>'''
59
74
60
75
def __init__ (self , attrs = None , format = None , options = None , div_attrs = None , icon_attrs = None ):
61
76
if not icon_attrs :
@@ -70,7 +85,7 @@ def __init__(self, attrs=None, format=None, options=None, div_attrs=None, icon_a
70
85
self .div_attrs = div_attrs and div_attrs .copy () or {}
71
86
self .icon_attrs = icon_attrs and icon_attrs .copy () or {}
72
87
self .picker_id = self .div_attrs .get ('id' ) or None
73
- if not options : # datetimepicker will not be initalized
88
+ if options == False : # datetimepicker will not be initalized only when options is False
74
89
self .options = False
75
90
else :
76
91
self .options = options and options .copy () or {}
@@ -93,23 +108,12 @@ def render(self, name, value, attrs=None):
93
108
div_attrs = dict (
94
109
[(key , conditional_escape (val )) for key , val in self .div_attrs .items ()]) # python2.6 compatible
95
110
icon_attrs = dict ([(key , conditional_escape (val )) for key , val in self .icon_attrs .items ()])
96
- html = '''
97
- <div%(div_attrs)s>
98
- <input%(input_attrs)s/>
99
- <span class="input-group-addon">
100
- <span%(icon_attrs)s></span>
101
- </span>
102
- </div>''' % dict (div_attrs = flatatt (div_attrs ),
103
- input_attrs = flatatt (input_attrs ),
104
- icon_attrs = flatatt (icon_attrs ))
111
+ html = self .html_template % dict (div_attrs = flatatt (div_attrs ),
112
+ input_attrs = flatatt (input_attrs ),
113
+ icon_attrs = flatatt (icon_attrs ))
105
114
if not self .options :
106
115
js = ''
107
116
else :
108
- js = '''
109
- <script>
110
- $(function() {
111
- $("#%(picker_id)s").datetimepicker(%(options)s);
112
- });
113
- </script>''' % dict (picker_id = picker_id ,
114
- options = json .dumps (self .options or {}))
117
+ js = self .js_template % dict (picker_id = picker_id ,
118
+ options = json .dumps (self .options or {}))
115
119
return mark_safe (force_text (html + js ))
0 commit comments