Skip to content

Commit

Permalink
Add SELECT2_LIB_VERSION setting
Browse files Browse the repository at this point in the history
The new setting allows to change to default library version to
a specific value without overriding all URLs individually.
  • Loading branch information
codingjoe committed Jul 24, 2018
1 parent 08ca1c1 commit 1954bf5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
9 changes: 6 additions & 3 deletions django_select2/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
class Select2Conf(AppConf):
"""Settings for Django-Select2."""

LIB_VERSION = '4.0.3'
"""Version of the Select2 library."""

CACHE_BACKEND = 'default'
"""
Django-Select2 uses Django's cache to sure a consistent state across multiple machines.
Expand Down Expand Up @@ -53,7 +56,7 @@ class Select2Conf(AppConf):
It has set `select2_` as a default value, which you can change if needed.
"""

JS = '//cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.min.js'
JS = f'//cdnjs.cloudflare.com/ajax/libs/select2/{LIB_VERSION}/js/select2.min.js'
"""
The URI for the Select2 JS file. By default this points to the Cloudflare CDN.
Expand All @@ -71,7 +74,7 @@ class Select2Conf(AppConf):
develop without an Internet connection.
"""

CSS = '//cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.min.css'
CSS = f'//cdnjs.cloudflare.com/ajax/libs/select2/{LIB_VERSION}/css/select2.min.css'

This comment has been minimized.

Copy link
@peterdemin

peterdemin Jul 24, 2018

f strings were added in Python 3.6. could you please revert this change, so I could continue using Python 3.4?

This comment has been minimized.

Copy link
@codingjoe

codingjoe Jul 27, 2018

Author Collaborator

hi @peterdemin I am sorry, but I won't revert this change. If you want to use an old version of Python, use an old version of this package. Please understand that I maintain this package in my free time. It is too much work to maintain all different Python versions.

Please also be aware that Python 3.4 EoL is approaching fast https://devguide.python.org/#status-of-python-branches
Please also be aware that Django is dropping support for 3.4 too.

This comment has been minimized.

Copy link
@peterdemin

peterdemin Jul 27, 2018

I totally understand lack of time. But dropping supported (for almost a year more) python version is a big step and should go in major release, instead of patch. 3.4 is the default in CentOS 7, which my company uses.
If you're concerned with semantic versioning, I would suggest releasing 4.0.0 with the package as it is now. And 3.8.2 with py34 support

This comment has been minimized.

Copy link
@codingjoe

codingjoe Jul 30, 2018

Author Collaborator

hi @peterdemin ok, I see what you mean. We never supported 3.5 in version 3.x though. Anyhow. I am not against a patch if you would provide one. If you can't I can create a major new release, but I can't roll back the already released version.

Again, if you want to invest time to patch this, I would be willing to merge.

This comment has been minimized.

Copy link
@peterdemin

peterdemin Jul 30, 2018

I don't think any code changes are necessary. Bump major version and release the master branch as is with 7.0.0.
Then check out 6.1.0 and re-release it with 6.1.2.
This way, everyone who has ~6.1 in the requirements file and python<3.6 will have a working version,
and everyone with python>=3.6 can upgrade to 7.0.0+ and have all the new fixes/features.
Removing releases from pypi is always a bad idea, in all such cases it's better to release the fix with the next version.

This comment has been minimized.

Copy link
@codingjoe

codingjoe Aug 5, 2018

Author Collaborator

I fixed it because it broke the docs build too.

"""
The URI for the Select2 CSS file. By default this points to the Cloudflare CDN.
Expand All @@ -89,7 +92,7 @@ class Select2Conf(AppConf):
develop without an Internet connection.
"""

I18N_PATH = '//cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/i18n'
I18N_PATH = f'//cdnjs.cloudflare.com/ajax/libs/select2/{LIB_VERSION}/js/i18n'
"""
The base URI for the Select2 i18n files. By default this points to the Cloudflare CDN.
Expand Down
27 changes: 14 additions & 13 deletions tests/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from selenium.webdriver.support.wait import WebDriverWait

from django_select2.cache import cache
from django_select2.conf import settings
from django_select2.forms import (
HeavySelect2MultipleWidget, HeavySelect2Widget, ModelSelect2TagWidget,
ModelSelect2Widget, Select2Widget
Expand Down Expand Up @@ -104,44 +105,44 @@ def test_empty_option(self, db):
def test_i18n(self):
translation.activate('de')
assert tuple(Select2Widget().media._js) == (
'//cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.min.js',
'//cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/i18n/de.js',
f'//cdnjs.cloudflare.com/ajax/libs/select2/{settings.SELECT2_LIB_VERSION}/js/select2.min.js',
f'//cdnjs.cloudflare.com/ajax/libs/select2/{settings.SELECT2_LIB_VERSION}/js/i18n/de.js',
'django_select2/django_select2.js'
)

translation.activate('en')
assert tuple(Select2Widget().media._js) == (
'//cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.min.js',
'//cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/i18n/en.js',
f'//cdnjs.cloudflare.com/ajax/libs/select2/{settings.SELECT2_LIB_VERSION}/js/select2.min.js',
f'//cdnjs.cloudflare.com/ajax/libs/select2/{settings.SELECT2_LIB_VERSION}/js/i18n/en.js',
'django_select2/django_select2.js'
)

translation.activate('00')
assert tuple(Select2Widget().media._js) == (
'//cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.min.js',
f'//cdnjs.cloudflare.com/ajax/libs/select2/{settings.SELECT2_LIB_VERSION}/js/select2.min.js',
'django_select2/django_select2.js'
)

translation.activate('sr-cyrl')
assert tuple(Select2Widget().media._js) == (
'//cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.min.js',
'//cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/i18n/sr-Cyrl.js',
f'//cdnjs.cloudflare.com/ajax/libs/select2/{settings.SELECT2_LIB_VERSION}/js/select2.min.js',
f'//cdnjs.cloudflare.com/ajax/libs/select2/{settings.SELECT2_LIB_VERSION}/js/i18n/sr-Cyrl.js',
'django_select2/django_select2.js'
)

pytest.importorskip("django", minversion="2.0.4")

translation.activate('zh-hans')
assert tuple(Select2Widget().media._js) == (
'//cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.min.js',
'//cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/i18n/zh-CN.js',
f'//cdnjs.cloudflare.com/ajax/libs/select2/{settings.SELECT2_LIB_VERSION}/js/select2.min.js',
f'//cdnjs.cloudflare.com/ajax/libs/select2/{settings.SELECT2_LIB_VERSION}/js/i18n/zh-CN.js',
'django_select2/django_select2.js'
)

translation.activate('zh-hant')
assert tuple(Select2Widget().media._js) == (
'//cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.min.js',
'//cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/i18n/zh-TW.js',
f'//cdnjs.cloudflare.com/ajax/libs/select2/{settings.SELECT2_LIB_VERSION}/js/select2.min.js',
f'//cdnjs.cloudflare.com/ajax/libs/select2/{settings.SELECT2_LIB_VERSION}/js/i18n/zh-TW.js',
'django_select2/django_select2.js'
)

Expand All @@ -150,8 +151,8 @@ class TestSelect2MixinSettings(object):
def test_default_media(self):
sut = Select2Widget()
result = sut.media.render()
assert '//cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.min.js' in result
assert '//cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.min.css' in result
assert f'//cdnjs.cloudflare.com/ajax/libs/select2/{settings.SELECT2_LIB_VERSION}/js/select2.min.js' in result
assert f'//cdnjs.cloudflare.com/ajax/libs/select2/{settings.SELECT2_LIB_VERSION}/css/select2.min.css' in result
assert 'django_select2/django_select2.js' in result

def test_js_setting(self, settings):
Expand Down

0 comments on commit 1954bf5

Please sign in to comment.