From: Dominik George <natureshadow@debian.org>
Date: Fri, 30 May 2025 00:24:55 +0100
Subject: Use local Select2.js by default

Last-Update: 2025-05-30
---
 django_select2/conf.py | 25 ++++++++++---------------
 tests/test_forms.py    | 30 +++++++++++++++---------------
 2 files changed, 25 insertions(+), 30 deletions(-)

diff --git a/django_select2/conf.py b/django_select2/conf.py
index 8862932..31d5b53 100644
--- a/django_select2/conf.py
+++ b/django_select2/conf.py
@@ -8,7 +8,7 @@ __all__ = ("settings", "Select2Conf")
 class Select2Conf(AppConf):
     """Settings for Django-Select2."""
 
-    LIB_VERSION = "4.0.12"
+    LIB_VERSION = "debian"
     """Version of the Select2 library."""
 
     CACHE_BACKEND = "default"
@@ -56,11 +56,10 @@ class Select2Conf(AppConf):
     It has set `select2_` as a default value, which you can change if needed.
     """
 
-    JS = "https://cdnjs.cloudflare.com/ajax/libs/select2/{version}/js/select2.min.js".format(
-        version=LIB_VERSION
-    )
+    JS = "django_select2/select2.js/select2.js"
     """
-    The URI for the Select2 JS file. By default this points to the Cloudflare CDN.
+    The URI for the Select2 JS file. By default this points to a local copy linked
+    to the libjs-select2.js Debian package, to be served via staticfiles.
 
     If you want to select the version of the JS library used, or want to serve it from
     the local 'static' resources, add a line to your settings.py like so::
@@ -76,11 +75,10 @@ class Select2Conf(AppConf):
         develop without an Internet connection.
     """
 
-    CSS = "https://cdnjs.cloudflare.com/ajax/libs/select2/{version}/css/select2.min.css".format(
-        version=LIB_VERSION
-    )
+    CSS = "django_select2/select2.js/select2.css"
     """
-    The URI for the Select2 CSS file. By default this points to the Cloudflare CDN.
+    The URI for the Select2 CSS file. By default this points to a local copy linked
+    to the libjs-select2.js Debian package, to be served via staticfiles.
 
     If you want to select the version of the library used, or want to serve it from
     the local 'static' resources, add a line to your settings.py like so::
@@ -112,13 +110,10 @@ class Select2Conf(AppConf):
     .. tip:: When using other themes, you may need use select2 css and theme css.
     """
 
-    I18N_PATH = (
-        "https://cdnjs.cloudflare.com/ajax/libs/select2/{version}/js/i18n".format(
-            version=LIB_VERSION
-        )
-    )
+    I18N_PATH = "django_select2/select2.js/i18n"
     """
-    The base URI for the Select2 i18n files. By default this points to the Cloudflare CDN.
+    The base URI for the Select2 i18n files. By default this points to a local copy linked
+    to the libjs-select2.js Debian package, to be served via staticfiles.
 
     If you want to select the version of the I18N library used, or want to serve it from
     the local 'static' resources, add a line to your settings.py like so::
diff --git a/tests/test_forms.py b/tests/test_forms.py
index dc991ed..9900330 100644
--- a/tests/test_forms.py
+++ b/tests/test_forms.py
@@ -129,28 +129,28 @@ class TestSelect2Mixin:
     def test_i18n(self):
         translation.activate("de")
         assert tuple(Select2Widget().media._js) == (
-            f"https://cdnjs.cloudflare.com/ajax/libs/select2/{settings.SELECT2_LIB_VERSION}/js/select2.min.js",
-            f"https://cdnjs.cloudflare.com/ajax/libs/select2/{settings.SELECT2_LIB_VERSION}/js/i18n/de.js",
+            "django_select2/select2.js/select2.js",
+            "django_select2/select2.js/i18n/de.js",
             "django_select2/django_select2.js",
         )
 
         translation.activate("en")
         assert tuple(Select2Widget().media._js) == (
-            f"https://cdnjs.cloudflare.com/ajax/libs/select2/{settings.SELECT2_LIB_VERSION}/js/select2.min.js",
-            f"https://cdnjs.cloudflare.com/ajax/libs/select2/{settings.SELECT2_LIB_VERSION}/js/i18n/en.js",
+            "django_select2/select2.js/select2.js",
+            "django_select2/select2.js/i18n/en.js",
             "django_select2/django_select2.js",
         )
 
         translation.activate("00")
         assert tuple(Select2Widget().media._js) == (
-            f"https://cdnjs.cloudflare.com/ajax/libs/select2/{settings.SELECT2_LIB_VERSION}/js/select2.min.js",
+            "django_select2/select2.js/select2.js",
             "django_select2/django_select2.js",
         )
 
         translation.activate("sr-cyrl")
         assert tuple(Select2Widget().media._js) == (
-            f"https://cdnjs.cloudflare.com/ajax/libs/select2/{settings.SELECT2_LIB_VERSION}/js/select2.min.js",
-            f"https://cdnjs.cloudflare.com/ajax/libs/select2/{settings.SELECT2_LIB_VERSION}/js/i18n/sr-Cyrl.js",
+            "django_select2/select2.js/select2.js",
+            "django_select2/select2.js/i18n/sr-Cyrl.js",
             "django_select2/django_select2.js",
         )
 
@@ -158,15 +158,15 @@ class TestSelect2Mixin:
 
         translation.activate("zh-hans")
         assert tuple(Select2Widget().media._js) == (
-            f"https://cdnjs.cloudflare.com/ajax/libs/select2/{settings.SELECT2_LIB_VERSION}/js/select2.min.js",
-            f"https://cdnjs.cloudflare.com/ajax/libs/select2/{settings.SELECT2_LIB_VERSION}/js/i18n/zh-CN.js",
+            "django_select2/select2.js/select2.js",
+            "django_select2/select2.js/i18n/zh-CN.js",
             "django_select2/django_select2.js",
         )
 
         translation.activate("zh-hant")
         assert tuple(Select2Widget().media._js) == (
-            f"https://cdnjs.cloudflare.com/ajax/libs/select2/{settings.SELECT2_LIB_VERSION}/js/select2.min.js",
-            f"https://cdnjs.cloudflare.com/ajax/libs/select2/{settings.SELECT2_LIB_VERSION}/js/i18n/zh-TW.js",
+            "django_select2/select2.js/select2.js",
+            "django_select2/select2.js/i18n/zh-TW.js",
             "django_select2/django_select2.js",
         )
 
@@ -180,8 +180,8 @@ class TestSelect2AdminMixin:
     def test_media(self):
         translation.activate("en")
         assert tuple(Select2AdminMixin().media._js) == (
-            f"https://cdnjs.cloudflare.com/ajax/libs/select2/{settings.SELECT2_LIB_VERSION}/js/select2.min.js",
-            f"https://cdnjs.cloudflare.com/ajax/libs/select2/{settings.SELECT2_LIB_VERSION}/js/i18n/en.js",
+            "django_select2/select2.js/select2.js",
+            "django_select2/select2.js/i18n/en.js",
             "django_select2/django_select2.js",
         )
 
@@ -198,11 +198,11 @@ class TestSelect2MixinSettings:
         sut = Select2Widget()
         result = sut.media.render()
         assert (
-            f"https://cdnjs.cloudflare.com/ajax/libs/select2/{settings.SELECT2_LIB_VERSION}/js/select2.min.js"
+            "django_select2/select2.js/select2.js"
             in result
         )
         assert (
-            f"https://cdnjs.cloudflare.com/ajax/libs/select2/{settings.SELECT2_LIB_VERSION}/css/select2.min.css"
+            "django_select2/select2.js/select2.css"
             in result
         )
         assert "django_select2/django_select2.js" in result
