Skip to content

Drop support for EOL Python and Django and update tests #313

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

Merged
merged 13 commits into from
Feb 9, 2025
Merged
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
9 changes: 4 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '12.x'
node-version-file: '.nvmrc'
- run: npm install -g standard
- run: standard

Expand All @@ -66,14 +66,13 @@ jobs:
strategy:
matrix:
python-version:
- "3.8"
- "3.9"
- "3.10"
- "3.11"
- "3.12"
- "3.13"
django-version:
- "3.2"
- "4.1"
- "4.2"
- "5.1"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lts/*
19 changes: 3 additions & 16 deletions django_select2/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@
from itertools import chain
from pickle import PicklingError # nosec

import django
from django import forms
from django.contrib.admin.utils import lookup_spawns_duplicates
from django.contrib.admin.widgets import AutocompleteMixin
from django.core import signing
from django.db.models import Q
Expand All @@ -71,13 +71,6 @@
from .cache import cache
from .conf import settings

if django.VERSION < (4, 0):
from django.contrib.admin.utils import (
lookup_needs_distinct as lookup_spawns_duplicates,
)
else:
from django.contrib.admin.utils import lookup_spawns_duplicates


class Select2Mixin:
"""
Expand All @@ -96,15 +89,9 @@ class Select2Mixin:
@property
def i18n_name(self):
"""Name of the i18n file for the current language."""
if django.VERSION < (4, 1):
from django.contrib.admin.widgets import SELECT2_TRANSLATIONS
from django.utils.translation import get_language

return SELECT2_TRANSLATIONS.get(get_language())
else:
from django.contrib.admin.widgets import get_select2_language
from django.contrib.admin.widgets import get_select2_language

return get_select2_language()
return get_select2_language()

def build_attrs(self, base_attrs, extra_attrs=None):
"""Add select2 data attributes."""
Expand Down
2 changes: 0 additions & 2 deletions example/example/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,6 @@

USE_I18N = True

USE_L10N = True

USE_TZ = True


Expand Down
11 changes: 5 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,18 @@ classifiers = [
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Framework :: Django",
"Framework :: Django :: 3.2",
"Framework :: Django :: 4.1",
"Framework :: Django :: 4.2",
"Framework :: Django :: 5.1",
"Topic :: Software Development",
]
requires-python = ">=3.8"
requires-python = ">=3.10"
dependencies = [
"django>=3.2",
"django>=4.2",
"django-appconf>=0.6.0"
]

Expand Down
32 changes: 1 addition & 31 deletions tests/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import os
from collections.abc import Iterable

import django
import pytest
from django.db.models import QuerySet
from django.urls import reverse
Expand Down Expand Up @@ -751,7 +750,7 @@ def test_widgets_selected_after_validation_error(
assert len(city_names_from_browser) != City.objects.count()
assert city_names_from_browser == city_names_from_db

# selecting a city reaaly does it
# selecting a city really does it
city_option = driver.find_element(
By.CSS_SELECTOR, ".select2-results li:nth-child(2)"
)
Expand Down Expand Up @@ -851,7 +850,6 @@ def widget_fixture(request):
return widget_class(**widget_kwargs)


@pytest.mark.skipif(django.VERSION < (4, 1), reason="Only for Django 4.1+")
@pytest.mark.parametrize(
"locale,expected",
[
Expand All @@ -868,38 +866,10 @@ def test_i18n_name_property_with_country_code_in_locale(widget, locale, expected
assert widget.i18n_name == expected


@pytest.mark.skipif(django.VERSION < (4, 1), reason="Only for Django 4.1+")
def test_i18n_media_js_with_country_code_in_locale(widget):
translation.activate("fr-FR")
assert tuple(widget.media._js) == (
"admin/js/vendor/select2/select2.full.min.js",
"admin/js/vendor/select2/i18n/fr.js",
"django_select2/django_select2.js",
)


@pytest.mark.skipif(django.VERSION >= (4, 1), reason="Only for Django 4.0 and previous")
@pytest.mark.parametrize(
"locale,expected",
[
("fr-FR", None),
# Some locales with a country code are natively supported by select2's i18n
("pt-BR", "pt-BR"),
("sr-Cyrl", "sr-Cyrl"),
],
)
def test_i18n_name_property_with_country_code_in_locale_for_older_django(
widget, locale, expected
):
"""No fallback for locale with an unsupported country code."""
with translation.override(locale):
assert widget.i18n_name == expected


@pytest.mark.skipif(django.VERSION >= (4, 1), reason="Only for Django 4.0 and previous")
def test_i18n_media_js_with_country_code_in_locale_for_older_django(widget):
translation.activate("fr-FR")
assert tuple(widget.media._js) == (
"admin/js/vendor/select2/select2.full.min.js",
"django_select2/django_select2.js",
)
6 changes: 1 addition & 5 deletions tests/test_views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json

from django.urls import reverse
from django.utils.encoding import smart_str

from django_select2.cache import cache
Expand All @@ -11,11 +12,6 @@
)
from tests.testapp.models import Genre

try:
from django.urls import reverse
except ImportError:
from django.core.urlresolvers import reverse


class TestAutoResponseView:
def test_get(self, client, artists):
Expand Down
4 changes: 0 additions & 4 deletions tests/testapp/settings.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import os.path

import django

BASE_DIR = os.path.dirname(os.path.abspath(__file__))
DEBUG = True

Expand Down Expand Up @@ -40,7 +38,5 @@

SECRET_KEY = "123456"

if django.VERSION < (4, 0):
USE_L10N = True
USE_I18N = True
USE_TZ = True