-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from JulianMaurin/feat/django4
feat(DateTimePicker): replace deprecated force_text (& add test)
- Loading branch information
Showing
4 changed files
with
48 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import django | ||
|
||
from bootstrap3_datetime.widgets import DateTimePicker | ||
|
||
|
||
class DateTimePickerDjango110(DateTimePicker): | ||
def build_attrs(self, base_attrs=None, extra_attrs=None, **kwargs): | ||
if extra_attrs: | ||
base_attrs.update(extra_attrs) | ||
base_attrs.update(kwargs) | ||
return super(DateTimePickerDjango110, self).build_attrs(**base_attrs) | ||
|
||
|
||
def is_legacy(): | ||
x,y,z = [int(v) for v in django.__version__.split(".")] | ||
return x == 1 and y < 11 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import json | ||
|
||
from legacy import DateTimePickerDjango110, is_legacy | ||
|
||
from bootstrap3_datetime.widgets import DateTimePicker | ||
|
||
|
||
def test_rendering(): | ||
options = {"pickTime": True, "format": "YYYY-MM-DD HH:mm"} | ||
widget = (DateTimePickerDjango110 if is_legacy() else DateTimePicker)(options=options) | ||
expected_output = '\n <div class="input-group date" id="_pickers">\n <input class="form-control" name="a" type="text" value="b"/>\n <span class="input-group-addon">\n <span class="glyphicon glyphicon-calendar"></span>\n </span>\n </div>\n <script>\n (function(window) {\n var callback = function() {\n $(function(){$("#_pickers:has(input:not([readonly],[disabled]))").datetimepicker(%s);});\n };\n if(window.addEventListener)\n window.addEventListener("load", callback, false);\n else if (window.attachEvent)\n window.attachEvent("onload", callback);\n else window.onload = callback;\n })(window);\n </script>' | ||
assert widget.render("a", "b", {}) == expected_output % json.dumps(options) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[tox] | ||
envlist = | ||
{py27}-{django10,django111} | ||
{py39}-{django10,django111,django20,django30,django40} | ||
|
||
[testenv] | ||
commands = | ||
pytest | ||
deps = | ||
pytest | ||
django10: django==1.10.* | ||
django111: django==1.11.* | ||
django20: django==2.0.* | ||
django30: django==3.0.* | ||
django40: django==4.0.* | ||
setenv = | ||
PYTHONPATH = {toxinidir} |