From deec35446ef3a5b36ef8d6b04672661738a626bd Mon Sep 17 00:00:00 2001 From: pdt Date: Fri, 27 Mar 2015 00:03:16 +0100 Subject: [PATCH] fixed jsquery defined @bottom --- .../templates/example/example.html | 24 +++++++++++------- datetimewidget/widgets.py | 25 ++++++++++--------- 2 files changed, 28 insertions(+), 21 deletions(-) diff --git a/dateTimeExample/formexample/templates/example/example.html b/dateTimeExample/formexample/templates/example/example.html index f35bce2..27d4928 100644 --- a/dateTimeExample/formexample/templates/example/example.html +++ b/dateTimeExample/formexample/templates/example/example.html @@ -1,10 +1,7 @@ - - - - + {% if bootstrap == 3 %} @@ -14,19 +11,14 @@ - Boostrap 3 django-datetime-widget demo {% else %} - Boostrap 2 django-datetime-widget demo {% endif %} - {% if form %} - {{ form.media }} - {% endif %} Fork me on GitHub @@ -89,5 +81,19 @@

Code

django-datetime-widget is developed by Alfredo Saglimbeni based on bootstrap-datetimepicker

+ + + + + + + + + + +{% if form %} + {{ form.media }} +{% endif %} + diff --git a/datetimewidget/widgets.py b/datetimewidget/widgets.py index b159c31..6fcaf6c 100644 --- a/datetimewidget/widgets.py +++ b/datetimewidget/widgets.py @@ -1,7 +1,7 @@ - __author__ = 'Alfredo Saglimbeni' from datetime import datetime +import json import re import uuid @@ -82,7 +82,6 @@ def get_supported_language(language_country_code): toPython_re = re.compile(r'\b(' + '|'.join(dateConversiontoPython.keys()) + r')\b') - dateConversiontoJavascript = { '%M': 'ii', '%m': 'mm', @@ -106,7 +105,9 @@ def get_supported_language(language_country_code): """, 3: """ @@ -116,7 +117,9 @@ def get_supported_language(language_country_code): """ } @@ -227,17 +230,15 @@ def render(self, name, value, attrs=None): self.options.setdefault('autoclose', True) # Build javascript options out of python dictionary - options_list = [] + options_list = {} for key, value in iter(self.options.items()): - options_list.append("%s: %s" % (key, quote(key, 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) + options_list[key] = quote(key, value) + js_options = json.dumps(options_list) + + # Use provided id or generate hex to avoid collisions in document + id = final_attrs.get('id', uuid.uuid4().hex) clearBtn = quote('clearBtn', self.options.get('clearBtn', 'true')) == 'true' - return mark_safe( BOOTSTRAP_INPUT_TEMPLATE[self.bootstrap_version] % dict(