Skip to content

Commit 00cbc25

Browse files
committed
Move the configuration into a JSON blob
1 parent 0e89101 commit 00cbc25

File tree

6 files changed

+21
-19
lines changed

6 files changed

+21
-19
lines changed

.pre-commit-config.yaml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,26 @@ repos:
1414
- id: mixed-line-ending
1515
- id: trailing-whitespace
1616
- repo: https://github.com/adamchainz/django-upgrade
17-
rev: 1.22.1
17+
rev: 1.24.0
1818
hooks:
1919
- id: django-upgrade
2020
args: [--target-version, "3.2"]
2121
- repo: https://github.com/astral-sh/ruff-pre-commit
22-
rev: "v0.8.0"
22+
rev: "v0.11.5"
2323
hooks:
2424
- id: ruff
2525
args: [--unsafe-fixes]
2626
- id: ruff-format
2727
- repo: https://github.com/biomejs/pre-commit
28-
rev: "v0.5.0"
28+
rev: "v1.9.4"
2929
hooks:
3030
- id: biome-check
31-
additional_dependencies: ["@biomejs/[email protected]"]
3231
args: [--unsafe]
3332
- repo: https://github.com/tox-dev/pyproject-fmt
34-
rev: v2.5.0
33+
rev: v2.5.1
3534
hooks:
3635
- id: pyproject-fmt
3736
- repo: https://github.com/abravalheri/validate-pyproject
38-
rev: v0.23
37+
rev: v0.24.1
3938
hooks:
4039
- id: validate-pyproject

CHANGELOG.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ Next version
88
- Removed mentions of the ``Template`` type from the docs and deprecated the
99
class. django-content-editor never used it, only FeinCMS did; feincms3 ships
1010
its own ``TemplateType`` type replacing it.
11+
- Prepared for the new object-based ``Script`` by moving from django-js-asset's
12+
``JS`` to a script without attributes, and moved the configuration into an
13+
inline JSON blob.
1114

1215

1316
7.2 (2025-01-27)

content_editor/admin.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from django.core import checks
99
from django.utils.text import capfirst
1010
from django.utils.translation import gettext
11-
from js_asset.js import JS
11+
from js_asset.js import JSON
1212

1313

1414
__all__ = ("ContentEditorInline", "ContentEditor", "allow_regions", "deny_regions")
@@ -220,13 +220,11 @@ def _content_editor_media(self, request, context):
220220
"admin/js/jquery.init.js",
221221
"content_editor/save_shortcut.js",
222222
"content_editor/tabbed_fieldsets.js",
223-
JS(
224-
"content_editor/content_editor.js",
225-
{
226-
"id": "content-editor-context",
227-
"data-context": self._content_editor_context(request, context),
228-
},
223+
JSON(
224+
self._content_editor_context(request, context),
225+
id="content-editor-context",
229226
),
227+
"content_editor/content_editor.js",
230228
],
231229
)
232230

content_editor/static/content_editor/content_editor.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/* global django,ContentEditor */
22
;(() => {
3-
const _contentEditorContext = document.currentScript.dataset.context
3+
const _contentEditorContext = document.getElementById(
4+
"content-editor-context",
5+
).textContent
46

57
function qs(sel, ctx = document) {
68
return ctx.querySelector(sel)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ dynamic = [
3535
]
3636
dependencies = [
3737
"django>=3.2",
38-
"django-js-asset",
38+
"django-js-asset>=3",
3939
]
4040
optional-dependencies.tests = [
4141
"coverage",

tests/testapp/test_content_editor.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,9 @@ def test_stuff(client):
7878
def test_admin(client):
7979
response = client.get(reverse("admin:testapp_article_add"))
8080

81-
assertContains(response, '_editor.js" data-context="{"', 1)
82-
assertContains(response, 'id="content-editor-context"></sc', 1)
81+
assertContains(
82+
response, '<script id="content-editor-context" type="application/json">'
83+
)
8384
assertContains(response, 'class="richtext"', 1)
8485
assertContains(
8586
response,
@@ -177,8 +178,7 @@ class ModelAdmin(ContentEditor):
177178

178179
assert ModelAdmin(Model, admin.AdminSite()).check() == [
179180
checks.Error(
180-
"ContentEditor models require a non-empty 'regions'"
181-
" attribute or property.",
181+
"ContentEditor models require a non-empty 'regions' attribute or property.",
182182
obj=ModelAdmin,
183183
id="content_editor.E002",
184184
)

0 commit comments

Comments
 (0)