File: use-local-select2.patch

package info (click to toggle)
django-select2 7.10.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 452 kB
  • sloc: python: 1,654; javascript: 66; makefile: 3
file content (155 lines) | stat: -rw-r--r-- 7,149 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
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