Skip to content

Commit 769f857

Browse files
committed
chore: django 5.x compatibility
1 parent afa332e commit 769f857

File tree

9 files changed

+229
-126
lines changed

9 files changed

+229
-126
lines changed

.github/workflows/test.yml

Lines changed: 82 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,42 @@
11
name: Test
22

3-
on: push
3+
on: [push, pull_request]
44

55
jobs:
66
build:
7-
runs-on: ubuntu-latest
87
strategy:
8+
fail-fast: false
99
matrix:
10-
python-version: [3.7, 3.8, 3.9]
10+
include:
11+
- django-version: "2.2"
12+
python-version: "3.8"
13+
- django-version: "2.2"
14+
python-version: "3.8"
15+
grappelli: "1"
16+
- django-version: "3.2"
17+
python-version: "3.9"
18+
- django-version: "3.2"
19+
python-version: "3.10"
20+
grappelli: "1"
21+
- django-version: "4.2"
22+
python-version: "3.10"
23+
- django-version: "4.2"
24+
python-version: "3.11"
25+
grappelli: "1"
26+
- django-version: "5.1"
27+
python-version: "3.12"
28+
- django-version: "5.2"
29+
python-version: "3.12"
30+
- django-version: "5.2"
31+
python-version: "3.13"
32+
grappelli: "1"
33+
34+
runs-on: ubuntu-latest
35+
name: Django ${{ matrix.django-version }} (Python ${{ matrix.python-version }})${{ matrix.grappelli == '1' && ' + grappelli' || '' }}${{ matrix.s3 == '1' && ' + s3' || '' }}
36+
env:
37+
PYTHON: ${{ matrix.python-version }}
38+
DJANGO: ${{ matrix.django-version }}
39+
GRAPPELLI: ${{ matrix.grappelli || '0' }}
1140

1241
steps:
1342
- uses: actions/checkout@v3
@@ -17,16 +46,59 @@ jobs:
1746
with:
1847
python-version: ${{ matrix.python-version }}
1948

20-
- name: Setup chromedriver
21-
uses: nanasess/[email protected]
22-
23-
- name: Install dependencies
49+
- name: Install tox
2450
run: |
25-
python -m pip install --upgrade pip
26-
pip install tox tox-gh-actions
51+
python3 -m pip install tox tox-gh-actions
2752
28-
- name: Test with tox
53+
- name: Run tests
2954
run: |
3055
tox -- -v --selenosis-driver=chrome-headless || \
3156
tox -- -v --selenosis-driver=chrome-headless || \
3257
tox -- -v --selenosis-driver=chrome-headless
58+
59+
- name: Upload junit xml
60+
if: always()
61+
uses: actions/upload-artifact@v4
62+
with:
63+
name: junit-reports-django-${{ matrix.django-version }}-python${{ matrix.python-version }}${{ matrix.grappelli == '1' && '-grappelli' || '' }}${{ matrix.s3 == '1' && '-s3' || '' }}-${{ github.sha }}
64+
path: reports/*.xml
65+
overwrite: true
66+
67+
- name: Combine coverage
68+
run: tox -e coverage-report
69+
70+
- name: Upload coverage
71+
uses: codecov/codecov-action@v5
72+
with:
73+
name: ${{ github.workflow }}
74+
files: .tox/coverage/coverage.xml
75+
env_vars: "DJANGO,GRAPPELLI,PYTHON"
76+
token: ${{ secrets.CODECOV_TOKEN }}
77+
78+
report:
79+
if: always()
80+
needs: build
81+
runs-on: ubuntu-latest
82+
name: "Report Test Results"
83+
steps:
84+
- uses: actions/download-artifact@v4
85+
with:
86+
merge-multiple: true
87+
88+
- name: Publish Unit Test Results
89+
if: always()
90+
uses: mikepenz/action-junit-report@1a91e26932fb7ba410a31fab1f09266a96d29971
91+
with:
92+
report_paths: ./*.xml
93+
require_tests: true
94+
fail_on_failure: true
95+
check_name: Test Report
96+
github_token: ${{ secrets.GITHUB_TOKEN }}
97+
98+
success:
99+
needs: [report]
100+
runs-on: ubuntu-latest
101+
name: Test Successful
102+
steps:
103+
- name: Success
104+
run: echo Test Successful

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ ghostdriver.log
1313
.tox
1414
venv/
1515
.python-version
16+
reports
17+
coverage.xml

pyproject.toml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
[build-system]
2+
build-backend = "setuptools.build_meta"
3+
requires = ["setuptools>=75.3.2"]
4+
5+
[project]
6+
name = "django-select2-forms"
7+
dynamic = ["version"]
8+
description = "Django form fields using the Select2 jQuery plugin"
9+
readme = "README.rst"
10+
license = { text = "BSD-2-Clause" }
11+
requires-python = ">=3"
12+
authors = [
13+
{ name = "The Atlantic", email = "[email protected]" },
14+
]
15+
classifiers = [
16+
"Development Status :: 5 - Production/Stable",
17+
"Environment :: Web Environment",
18+
"Framework :: Django",
19+
"Framework :: Django :: 2.2",
20+
"Framework :: Django :: 3.2",
21+
"Framework :: Django :: 4.2",
22+
"Framework :: Django :: 5.0",
23+
"Framework :: Django :: 5.1",
24+
"Framework :: Django :: 5.2",
25+
"Programming Language :: Python :: 3 :: Only",
26+
"Programming Language :: Python :: 3.7",
27+
"Programming Language :: Python :: 3.8",
28+
"Programming Language :: Python :: 3.9",
29+
"Programming Language :: Python :: 3.10",
30+
"Programming Language :: Python :: 3.11",
31+
"Programming Language :: Python :: 3.12",
32+
"Programming Language :: Python :: 3.13",
33+
]
34+
dependencies = [
35+
"django-sortedm2m",
36+
]
37+
38+
[project.urls]
39+
Homepage = "https://github.com/theatlantic/django-select2-forms"
40+
41+
[tool.setuptools]
42+
zip-safe = false
43+
platforms = ["any"]
44+
include-package-data = true
45+
46+
[tool.setuptools.packages.find]
47+
include = ["select2*"]
48+
namespaces = false
49+
50+
[tool.setuptools.dynamic]
51+
version = { attr = "select2.__version__" }
52+
readme = { file = ["README.rst"] }
53+
54+
[tool.pytest.ini_options]
55+
python_files = "tests.py test_*.py *_test.py"
56+
DJANGO_SETTINGS_MODULE = "tests.settings"
57+
addopts = "--tb=short --create-db --cov=select2 --cov-branch --cov-report=xml"
58+
django_find_project = false
59+
testpaths = "tests"
60+
pythonpath = "."

select2/__init__.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1 @@
1-
import pkg_resources
2-
3-
try:
4-
__version__ = pkg_resources.get_distribution('django-select2-forms').version
5-
except pkg_resources.DistributionNotFound:
6-
__version__ = None
1+
__version__ = "3.1.0"

select2/fields.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,7 @@ def choices(self):
7979

8080
@choices.setter
8181
def choices(self, value):
82-
self._set_choices(value)
83-
84-
def _set_choices(self, value):
85-
self._choices = value
82+
super(self.__class__, self.__class__).choices.__set__(self, value)
8683

8784

8885
class ChoiceField(Select2FieldMixin, forms.ChoiceField):
@@ -133,12 +130,15 @@ def __init__(self, search_field=None, case_sensitive=False, *args, **kwargs):
133130
self.choice_iterator_cls = kwargs.pop('choice_iterator_cls', self.choice_iterator_cls)
134131
super(Select2ModelFieldMixin, self).__init__(*args, **kwargs)
135132

136-
def _get_choices(self):
137-
if hasattr(self, '_choices'):
138-
return self._choices
133+
@property
134+
def choices(self):
135+
if not hasattr(self, '_choices'):
139136
return self.choice_iterator_cls(self)
137+
return self._choices
140138

141-
choices = property(_get_choices, forms.ChoiceField._set_choices)
139+
@choices.setter
140+
def choices(self, value):
141+
super(self.__class__, self.__class__).choices.__set__(self, value)
142142

143143

144144
class ModelChoiceField(Select2ModelFieldMixin, forms.ModelChoiceField):

setup.py

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,3 @@
1-
#!/usr/bin/env python
2-
import codecs
3-
import os
4-
from setuptools import setup, find_packages
1+
from setuptools import setup
52

6-
readme_rst = os.path.join(os.path.dirname(__file__), 'README.rst')
7-
8-
setup(
9-
name='django-select2-forms',
10-
version='3.0.0',
11-
description='Django form fields using the Select2 jQuery plugin',
12-
long_description=codecs.open(readme_rst, encoding='utf-8').read(),
13-
author='Frankie Dintino',
14-
author_email='[email protected]',
15-
url='https://github.com/theatlantic/django-select2-forms',
16-
packages=find_packages(),
17-
license='BSD',
18-
platforms='any',
19-
install_requires=[
20-
'django-sortedm2m',
21-
],
22-
classifiers=[
23-
'Development Status :: 5 - Production/Stable',
24-
'Environment :: Web Environment',
25-
'Intended Audience :: Developers',
26-
'Operating System :: OS Independent',
27-
'Programming Language :: Python',
28-
'Framework :: Django',
29-
'Framework :: Django :: 2.2',
30-
'Framework :: Django :: 3.1',
31-
'Framework :: Django :: 3.2',
32-
'Programming Language :: Python',
33-
'Programming Language :: Python :: 3',
34-
'Programming Language :: Python :: 3.7',
35-
'Programming Language :: Python :: 3.8',
36-
'Programming Language :: Python :: 3.9',
37-
38-
],
39-
include_package_data=True,
40-
zip_safe=False
41-
)
3+
setup()

tests/settings.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@
1818
'tests',
1919
]
2020

21+
try:
22+
import grappelli # noqa
23+
except ImportError:
24+
pass
25+
else:
26+
INSTALLED_APPS.insert(0, 'grappelli')
27+
2128
MIDDLEWARE = [
2229
'django.middleware.security.SecurityMiddleware',
2330
'django.contrib.sessions.middleware.SessionMiddleware',

tests/test_admin.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from django.conf import settings
66
from selenosis.testcases import AdminSelenosisTestCase
77
from selenium.webdriver.common.keys import Keys
8+
from selenium.webdriver.common.by import By
89

910
from .models import Author, Publisher, Book, Library
1011

@@ -93,7 +94,8 @@ def get_count():
9394
yield el
9495

9596
def get_dropdown_count(self):
96-
return len(self.selenium.find_elements_by_css_selector(
97+
return len(self.selenium.find_elements(
98+
By.CSS_SELECTOR,
9799
'.select2-drop-active .select2-results '
98100
'.select2-result-selectable:not(.select2-selected)'))
99101

0 commit comments

Comments
 (0)