Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

attempt to fix #61 #72

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions dateTimeExample/formexample/templates/example/example.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">var switchTo5x=true;</script>
<script type="text/javascript" src="http://w.sharethis.com/button/buttons.js"></script>
<script type="text/javascript">stLight.options({publisher: "48952996-13d3-49f3-9854-e6438041a4b3", doNotHash: false, doNotCopy: false, hashAddressBar: false});</script>

<meta property="og:description" content="Bootstrap django-datetime-widget is a simple and clean widget for DateField, Timefiled and DateTimeField in Django framework. It is based on Bootstrap datetime picker, supports both Bootstrap 3 and Bootstrap 2" />
{% if bootstrap == 3 %}
<!-- Latest compiled and minified CSS -->
Expand All @@ -14,19 +11,14 @@
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">

<!-- Latest compiled and minified JavaScript -->
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<title>Boostrap 3 django-datetime-widget demo</title>
{% else %}
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/2.3.2/css/bootstrap.min.css">
<!-- Latest compiled and minified JavaScript -->
<script src="//maxcdn.bootstrapcdn.com/bootstrap/2.3.2/js/bootstrap.min.js"></script>
<title>Boostrap 2 django-datetime-widget demo</title>
{% endif %}

{% if form %}
{{ form.media }}
{% endif %}
</head>
<body>
<a href="http://bit.ly/django-datetime-widget"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/e7bbb0521b397edbd5fe43e7f760759336b5e05f/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f677265656e5f3030373230302e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_green_007200.png"></a>
Expand Down Expand Up @@ -89,5 +81,19 @@ <h3>Code</h3>
<p><a href="http://bit.ly/django-datetime-widget"> django-datetime-widget </a> is developed by <a href="http://bit.ly/asaglimbeni">Alfredo Saglimbeni</a> based on <a href="https://github.com/smalot/bootstrap-datetimepicker">bootstrap-datetimepicker</a> </p>
</div>
</div>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">var switchTo5x=true;</script>
<script type="text/javascript" src="http://w.sharethis.com/button/buttons.js"></script>
<script type="text/javascript">stLight.options({publisher: "48952996-13d3-49f3-9854-e6438041a4b3", doNotHash: false, doNotCopy: false, hashAddressBar: false});</script>

<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/2.3.2/js/bootstrap.min.js"></script>


{% if form %}
{{ form.media }}
{% endif %}

</body>
</html>
25 changes: 13 additions & 12 deletions datetimewidget/widgets.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

__author__ = 'Alfredo Saglimbeni'

from datetime import datetime
import json
import re
import uuid

Expand Down Expand Up @@ -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',
Expand All @@ -106,7 +105,9 @@ def get_supported_language(language_country_code):
<span class="add-on"><i class="icon-th"></i></span>
</div>
<script type="text/javascript">
$("#%(id)s").datetimepicker({%(options)s});
document.addEventListener("DOMContentLoaded", function(event) {
$("#%(id)s").datetimepicker(%(options)s);
});
</script>
""",
3: """
Expand All @@ -116,7 +117,9 @@ def get_supported_language(language_country_code):
<span class="input-group-addon"><span class="glyphicon %(glyphicon)s"></span></span>
</div>
<script type="text/javascript">
$("#%(id)s").datetimepicker({%(options)s}).find('input').addClass("form-control");
document.addEventListener("DOMContentLoaded", function(event) {
$("#%(id)s").datetimepicker(%(options)s).find('input').addClass("form-control");
});
</script>
"""
}
Expand Down Expand Up @@ -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(
Expand Down