django-json-widget 2.0.4__tar.gz → 2.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. {django_json_widget-2.0.4 → django_json_widget-2.1.0}/CHANGELOG.rst +5 -0
  2. {django_json_widget-2.0.4 → django_json_widget-2.1.0}/PKG-INFO +29 -1
  3. {django_json_widget-2.0.4 → django_json_widget-2.1.0}/README.rst +23 -0
  4. django_json_widget-2.1.0/django_json_widget/__init__.py +1 -0
  5. {django_json_widget-2.0.4 → django_json_widget-2.1.0}/django_json_widget/templates/django_json_widget.html +4 -0
  6. {django_json_widget-2.0.4 → django_json_widget-2.1.0}/django_json_widget.egg-info/PKG-INFO +29 -1
  7. {django_json_widget-2.0.4 → django_json_widget-2.1.0}/django_json_widget.egg-info/SOURCES.txt +3 -1
  8. {django_json_widget-2.0.4 → django_json_widget-2.1.0}/pyproject.toml +16 -1
  9. {django_json_widget-2.0.4 → django_json_widget-2.1.0}/setup.cfg +1 -1
  10. {django_json_widget-2.0.4 → django_json_widget-2.1.0}/setup.py +1 -1
  11. django_json_widget-2.1.0/tests/settings.py +49 -0
  12. django_json_widget-2.1.0/tests/templates/django/forms/widgets/attrs.html +1 -0
  13. django_json_widget-2.1.0/tests/test_jsoneditor_access.py +60 -0
  14. django_json_widget-2.0.4/django_json_widget/__init__.py +0 -1
  15. django_json_widget-2.0.4/tests/settings.py +0 -23
  16. {django_json_widget-2.0.4 → django_json_widget-2.1.0}/.coveragerc +0 -0
  17. {django_json_widget-2.0.4 → django_json_widget-2.1.0}/.editorconfig +0 -0
  18. {django_json_widget-2.0.4 → django_json_widget-2.1.0}/.github/ISSUE_TEMPLATE.md +0 -0
  19. {django_json_widget-2.0.4 → django_json_widget-2.1.0}/.github/workflows/tests.yml +0 -0
  20. {django_json_widget-2.0.4 → django_json_widget-2.1.0}/.gitignore +0 -0
  21. {django_json_widget-2.0.4 → django_json_widget-2.1.0}/.travis.yml +0 -0
  22. {django_json_widget-2.0.4 → django_json_widget-2.1.0}/AUTHORS.rst +0 -0
  23. {django_json_widget-2.0.4 → django_json_widget-2.1.0}/CONTRIBUTING.md +0 -0
  24. {django_json_widget-2.0.4 → django_json_widget-2.1.0}/LICENSE +0 -0
  25. {django_json_widget-2.0.4 → django_json_widget-2.1.0}/MANIFEST.in +0 -0
  26. {django_json_widget-2.0.4 → django_json_widget-2.1.0}/Makefile +0 -0
  27. {django_json_widget-2.0.4 → django_json_widget-2.1.0}/django_json_widget/apps.py +0 -0
  28. {django_json_widget-2.0.4 → django_json_widget-2.1.0}/django_json_widget/models.py +0 -0
  29. {django_json_widget-2.0.4 → django_json_widget-2.1.0}/django_json_widget/static/css/django_json_widget.css +0 -0
  30. {django_json_widget-2.0.4 → django_json_widget-2.1.0}/django_json_widget/static/dist/img/jsoneditor-icons.svg +0 -0
  31. {django_json_widget-2.0.4 → django_json_widget-2.1.0}/django_json_widget/static/dist/jsoneditor.min.css +0 -0
  32. {django_json_widget-2.0.4 → django_json_widget-2.1.0}/django_json_widget/static/dist/jsoneditor.min.js +0 -0
  33. {django_json_widget-2.0.4 → django_json_widget-2.1.0}/django_json_widget/urls.py +0 -0
  34. {django_json_widget-2.0.4 → django_json_widget-2.1.0}/django_json_widget/views.py +0 -0
  35. {django_json_widget-2.0.4 → django_json_widget-2.1.0}/django_json_widget/widgets.py +0 -0
  36. {django_json_widget-2.0.4 → django_json_widget-2.1.0}/django_json_widget.egg-info/dependency_links.txt +0 -0
  37. {django_json_widget-2.0.4 → django_json_widget-2.1.0}/django_json_widget.egg-info/not-zip-safe +0 -0
  38. {django_json_widget-2.0.4 → django_json_widget-2.1.0}/django_json_widget.egg-info/top_level.txt +0 -0
  39. {django_json_widget-2.0.4 → django_json_widget-2.1.0}/example/README.md +0 -0
  40. {django_json_widget-2.0.4 → django_json_widget-2.1.0}/example/characters/__init__.py +0 -0
  41. {django_json_widget-2.0.4 → django_json_widget-2.1.0}/example/characters/admin.py +0 -0
  42. {django_json_widget-2.0.4 → django_json_widget-2.1.0}/example/characters/apps.py +0 -0
  43. {django_json_widget-2.0.4 → django_json_widget-2.1.0}/example/characters/migrations/0001_initial.py +0 -0
  44. {django_json_widget-2.0.4 → django_json_widget-2.1.0}/example/characters/migrations/0002_alter_character_data_alter_character_other_data.py +0 -0
  45. {django_json_widget-2.0.4 → django_json_widget-2.1.0}/example/characters/migrations/__init__.py +0 -0
  46. {django_json_widget-2.0.4 → django_json_widget-2.1.0}/example/characters/models.py +0 -0
  47. {django_json_widget-2.0.4 → django_json_widget-2.1.0}/example/characters/tests.py +0 -0
  48. {django_json_widget-2.0.4 → django_json_widget-2.1.0}/example/characters/views.py +0 -0
  49. {django_json_widget-2.0.4 → django_json_widget-2.1.0}/example/example/__init__.py +0 -0
  50. {django_json_widget-2.0.4 → django_json_widget-2.1.0}/example/example/settings.py +0 -0
  51. {django_json_widget-2.0.4 → django_json_widget-2.1.0}/example/example/urls.py +0 -0
  52. {django_json_widget-2.0.4 → django_json_widget-2.1.0}/example/example/wsgi.py +0 -0
  53. {django_json_widget-2.0.4 → django_json_widget-2.1.0}/example/manage.py +0 -0
  54. {django_json_widget-2.0.4 → django_json_widget-2.1.0}/example/requirements.txt +0 -0
  55. {django_json_widget-2.0.4 → django_json_widget-2.1.0}/example/templates/django_json_widget/base.html +0 -0
  56. {django_json_widget-2.0.4 → django_json_widget-2.1.0}/imgs/jsonfield_0.png +0 -0
  57. {django_json_widget-2.0.4 → django_json_widget-2.1.0}/imgs/jsonfield_1.png +0 -0
  58. {django_json_widget-2.0.4 → django_json_widget-2.1.0}/manage.py +0 -0
  59. {django_json_widget-2.0.4 → django_json_widget-2.1.0}/requirements.txt +0 -0
  60. {django_json_widget-2.0.4 → django_json_widget-2.1.0}/requirements_dev.txt +0 -0
  61. {django_json_widget-2.0.4 → django_json_widget-2.1.0}/requirements_test.txt +0 -0
  62. {django_json_widget-2.0.4 → django_json_widget-2.1.0}/tests/__init__.py +0 -0
  63. {django_json_widget-2.0.4 → django_json_widget-2.1.0}/tests/test_logic.py +0 -0
  64. {django_json_widget-2.0.4 → django_json_widget-2.1.0}/tests/test_widget_security.py +0 -0
  65. {django_json_widget-2.0.4 → django_json_widget-2.1.0}/tox.ini +0 -0
@@ -2,6 +2,11 @@
2
2
  Changelog
3
3
  =========
4
4
 
5
+ 2.1.0 (2025-10-24)
6
+ ------------------
7
+
8
+ * Issue #114: expose editor instance to window object and DOM element.
9
+
5
10
  2.0.4 (2025-10-11)
6
11
  ------------------
7
12
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: django-json-widget
3
- Version: 2.0.4
3
+ Version: 2.1.0
4
4
  Summary: Django json widget is an alternative widget that makes it easy to edit the jsonfield field of django.
5
5
  Home-page: https://github.com/jmrivas86/django-json-widget
6
6
  Author: José Manuel Rivas
@@ -108,6 +108,29 @@ You can customize the JSONEditorWidget with the following options:
108
108
  * **mode (deprecated)**: The default editor mode. This argument is redundant because it can be specified as a part of ``options``. Preserved for backwards compatibility with version 0.2.0.
109
109
  * **attrs**: HTML attributes to be applied to the wrapper element. See the `Django Widget documentation`_.
110
110
 
111
+ Accessing JsonEditor Instance
112
+ -----------------------------
113
+
114
+ The JsonEditor instance is automatically exposed for external access through two methods:
115
+
116
+ 1. **Window object**: Available as ``window['FIELD_ID_editor']`` where FIELD_ID is the field's HTML ID
117
+ 2. **DOM element**: Available as ``container.jsonEditor`` property on the widget's container element
118
+
119
+ Example usage for external JavaScript access:
120
+
121
+ .. code-block:: javascript
122
+
123
+ // Access via window object
124
+ var editor = window['id_jsonfield_editor'];
125
+ editor.set({'key': 'new value'});
126
+
127
+ // Access via DOM element
128
+ var container = document.getElementById('id_jsonfield');
129
+ var editor = container.jsonEditor;
130
+ editor.set({'key': 'new value'});
131
+
132
+ This allows you to programmatically call JsonEditor methods like ``set()``, ``get()``, ``update()``, etc. from custom JavaScript code running in your admin pages or forms.
133
+
111
134
  .. _json editor: https://github.com/josdejong/jsoneditor/blob/master/docs/api.md#configuration-options
112
135
  .. _Django Widget documentation: https://docs.djangoproject.com/en/2.1/ref/forms/widgets/#django.forms.Widget.attrs
113
136
 
@@ -146,6 +169,11 @@ Tools used in rendering this package:
146
169
  Changelog
147
170
  =========
148
171
 
172
+ 2.1.0 (2025-10-24)
173
+ ------------------
174
+
175
+ * Issue #114: expose editor instance to window object and DOM element.
176
+
149
177
  2.0.4 (2025-10-11)
150
178
  ------------------
151
179
 
@@ -72,6 +72,29 @@ You can customize the JSONEditorWidget with the following options:
72
72
  * **mode (deprecated)**: The default editor mode. This argument is redundant because it can be specified as a part of ``options``. Preserved for backwards compatibility with version 0.2.0.
73
73
  * **attrs**: HTML attributes to be applied to the wrapper element. See the `Django Widget documentation`_.
74
74
 
75
+ Accessing JsonEditor Instance
76
+ -----------------------------
77
+
78
+ The JsonEditor instance is automatically exposed for external access through two methods:
79
+
80
+ 1. **Window object**: Available as ``window['FIELD_ID_editor']`` where FIELD_ID is the field's HTML ID
81
+ 2. **DOM element**: Available as ``container.jsonEditor`` property on the widget's container element
82
+
83
+ Example usage for external JavaScript access:
84
+
85
+ .. code-block:: javascript
86
+
87
+ // Access via window object
88
+ var editor = window['id_jsonfield_editor'];
89
+ editor.set({'key': 'new value'});
90
+
91
+ // Access via DOM element
92
+ var container = document.getElementById('id_jsonfield');
93
+ var editor = container.jsonEditor;
94
+ editor.set({'key': 'new value'});
95
+
96
+ This allows you to programmatically call JsonEditor methods like ``set()``, ``get()``, ``update()``, etc. from custom JavaScript code running in your admin pages or forms.
97
+
75
98
  .. _json editor: https://github.com/josdejong/jsoneditor/blob/master/docs/api.md#configuration-options
76
99
  .. _Django Widget documentation: https://docs.djangoproject.com/en/2.1/ref/forms/widgets/#django.forms.Widget.attrs
77
100
 
@@ -0,0 +1 @@
1
+ __version__ = '2.1.0'
@@ -21,5 +21,9 @@
21
21
  var content = document.getElementById("{{ widget.name }}_data").textContent;
22
22
  textarea.value = content;
23
23
  editor.set(JSON.parse(content));
24
+
25
+ // Expose editor instance for external access
26
+ window['{{ widget.attrs.id }}_editor'] = editor;
27
+ container.jsonEditor = editor;
24
28
  })();
25
29
  </script>
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: django-json-widget
3
- Version: 2.0.4
3
+ Version: 2.1.0
4
4
  Summary: Django json widget is an alternative widget that makes it easy to edit the jsonfield field of django.
5
5
  Home-page: https://github.com/jmrivas86/django-json-widget
6
6
  Author: José Manuel Rivas
@@ -108,6 +108,29 @@ You can customize the JSONEditorWidget with the following options:
108
108
  * **mode (deprecated)**: The default editor mode. This argument is redundant because it can be specified as a part of ``options``. Preserved for backwards compatibility with version 0.2.0.
109
109
  * **attrs**: HTML attributes to be applied to the wrapper element. See the `Django Widget documentation`_.
110
110
 
111
+ Accessing JsonEditor Instance
112
+ -----------------------------
113
+
114
+ The JsonEditor instance is automatically exposed for external access through two methods:
115
+
116
+ 1. **Window object**: Available as ``window['FIELD_ID_editor']`` where FIELD_ID is the field's HTML ID
117
+ 2. **DOM element**: Available as ``container.jsonEditor`` property on the widget's container element
118
+
119
+ Example usage for external JavaScript access:
120
+
121
+ .. code-block:: javascript
122
+
123
+ // Access via window object
124
+ var editor = window['id_jsonfield_editor'];
125
+ editor.set({'key': 'new value'});
126
+
127
+ // Access via DOM element
128
+ var container = document.getElementById('id_jsonfield');
129
+ var editor = container.jsonEditor;
130
+ editor.set({'key': 'new value'});
131
+
132
+ This allows you to programmatically call JsonEditor methods like ``set()``, ``get()``, ``update()``, etc. from custom JavaScript code running in your admin pages or forms.
133
+
111
134
  .. _json editor: https://github.com/josdejong/jsoneditor/blob/master/docs/api.md#configuration-options
112
135
  .. _Django Widget documentation: https://docs.djangoproject.com/en/2.1/ref/forms/widgets/#django.forms.Widget.attrs
113
136
 
@@ -146,6 +169,11 @@ Tools used in rendering this package:
146
169
  Changelog
147
170
  =========
148
171
 
172
+ 2.1.0 (2025-10-24)
173
+ ------------------
174
+
175
+ * Issue #114: expose editor instance to window object and DOM element.
176
+
149
177
  2.0.4 (2025-10-11)
150
178
  ------------------
151
179
 
@@ -56,5 +56,7 @@ imgs/jsonfield_0.png
56
56
  imgs/jsonfield_1.png
57
57
  tests/__init__.py
58
58
  tests/settings.py
59
+ tests/test_jsoneditor_access.py
59
60
  tests/test_logic.py
60
- tests/test_widget_security.py
61
+ tests/test_widget_security.py
62
+ tests/templates/django/forms/widgets/attrs.html
@@ -135,4 +135,19 @@ docstring-code-format = true
135
135
 
136
136
  # Set the line length limit used when formatting code snippets in
137
137
  # docstrings.
138
- docstring-code-line-length = "dynamic"
138
+ docstring-code-line-length = "dynamic"
139
+
140
+ [tool.pytest.ini_options]
141
+ python_files = ["test_*.py", "*_test.py"]
142
+ testpaths = ["tests"]
143
+ addopts = [
144
+ "--strict-markers",
145
+ "--strict-config",
146
+ "--verbose",
147
+ "--reuse-db",
148
+ ]
149
+ markers = [
150
+ "slow: marks tests as slow (deselect with '-m \"not slow\"')",
151
+ "integration: marks tests as integration tests",
152
+ ]
153
+ DJANGO_SETTINGS_MODULE = "tests.settings"
@@ -1,5 +1,5 @@
1
1
  [bumpversion]
2
- current_version = 2.0.4
2
+ current_version = 2.1.0
3
3
  commit = True
4
4
  tag = True
5
5
 
@@ -46,7 +46,7 @@ history = open('CHANGELOG.rst').read().replace('.. :changelog:', '')
46
46
 
47
47
  setup(
48
48
  name='django-json-widget',
49
- version='2.0.4',
49
+ version='2.1.0',
50
50
  description="""Django json widget is an alternative widget that makes it easy to edit the jsonfield field of django.""",
51
51
  long_description=readme + '\n\n' + history,
52
52
  author='José Manuel Rivas',
@@ -0,0 +1,49 @@
1
+ DEBUG = True
2
+ USE_TZ = True
3
+
4
+ # SECURITY WARNING: keep the secret key used in production secret!
5
+ SECRET_KEY = "uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu"
6
+
7
+ DATABASES = {
8
+ "default": {
9
+ "ENGINE": "django.db.backends.sqlite3",
10
+ "NAME": ":memory:",
11
+ }
12
+ }
13
+
14
+ INSTALLED_APPS = [
15
+ "django.contrib.auth",
16
+ "django.contrib.contenttypes",
17
+ "django.contrib.sites",
18
+ "django_json_widget",
19
+ ]
20
+
21
+ SITE_ID = 1
22
+
23
+ MIDDLEWARE = ()
24
+
25
+ # JSON Editor Widget Settings
26
+ JSON_EDITOR_JS = 'dist/jsoneditor.min.js'
27
+ JSON_EDITOR_CSS = 'dist/jsoneditor.min.css'
28
+
29
+ # Template configuration
30
+ TEMPLATES = [
31
+ {
32
+ 'BACKEND': 'django.template.backends.django.DjangoTemplates',
33
+ 'DIRS': ['tests/templates'],
34
+ 'APP_DIRS': True,
35
+ 'OPTIONS': {
36
+ 'context_processors': [
37
+ 'django.template.context_processors.debug',
38
+ 'django.template.context_processors.request',
39
+ 'django.contrib.auth.context_processors.auth',
40
+ 'django.contrib.messages.context_processors.messages',
41
+ ],
42
+ 'builtins': [
43
+ 'django.template.defaulttags',
44
+ 'django.template.defaultfilters',
45
+ 'django.template.loader_tags',
46
+ ],
47
+ },
48
+ },
49
+ ]
@@ -0,0 +1 @@
1
+ {% for name, value in widget.attrs.items %}{% if value is not False %} {{ name }}{% if value is not True %}="{{ value|stringformat:'s' }}"{% endif %}{% endif %}{% endfor %}
@@ -0,0 +1,60 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+
4
+ """
5
+ test_jsoneditor_access
6
+ ----------------------
7
+
8
+ Tests for JsonEditor instance accessibility from external JavaScript.
9
+ """
10
+
11
+ from django.template import Context, Template
12
+ from django.test import TestCase
13
+
14
+ from django_json_widget.widgets import JSONEditorWidget
15
+
16
+
17
+ class JSONEditorAccessTests(TestCase):
18
+ """Test JsonEditor instance accessibility"""
19
+
20
+ def test_template_exposes_editor_to_window(self):
21
+ """Test that JsonEditor instance is exposed to window object"""
22
+ widget = JSONEditorWidget()
23
+ context = widget.get_context("test_field", '{"key": "value"}', {"id": "test_id"})
24
+
25
+ # Render the template
26
+ template = Template('{% load static %}{% include "django_json_widget.html" %}')
27
+ rendered = template.render(Context({"widget": context["widget"]}))
28
+
29
+ # Check that the window assignment code is present
30
+ self.assertIn("window['test_id_editor'] = editor", rendered)
31
+
32
+ def test_template_exposes_editor_to_dom(self):
33
+ """Test that JsonEditor instance is attached to DOM container"""
34
+ widget = JSONEditorWidget()
35
+ context = widget.get_context("test_field", '{"key": "value"}', {"id": "test_id"})
36
+
37
+ # Render the template
38
+ template = Template('{% load static %}{% include "django_json_widget.html" %}')
39
+ rendered = template.render(Context({"widget": context["widget"]}))
40
+
41
+ # Check that the DOM assignment code is present
42
+ self.assertIn("container.jsonEditor = editor", rendered)
43
+
44
+ def test_multiple_widgets_different_ids(self):
45
+ """Test that multiple widgets get different window object names"""
46
+ widget1 = JSONEditorWidget()
47
+ widget2 = JSONEditorWidget()
48
+
49
+ context1 = widget1.get_context("field1", "{}", {"id": "id_field1"})
50
+ context2 = widget2.get_context("field2", "{}", {"id": "id_field2"})
51
+
52
+ template = Template('{% load static %}{% include "django_json_widget.html" %}')
53
+
54
+ rendered1 = template.render(Context({"widget": context1["widget"]}))
55
+ rendered2 = template.render(Context({"widget": context2["widget"]}))
56
+
57
+ # Each widget should have its own unique window object name
58
+ self.assertIn("window['id_field1_editor'] = editor", rendered1)
59
+ self.assertIn("window['id_field2_editor'] = editor", rendered2)
60
+ self.assertNotEqual(rendered1, rendered2)
@@ -1 +0,0 @@
1
- __version__ = '2.0.4'
@@ -1,23 +0,0 @@
1
- DEBUG = True
2
- USE_TZ = True
3
-
4
- # SECURITY WARNING: keep the secret key used in production secret!
5
- SECRET_KEY = "uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu"
6
-
7
- DATABASES = {
8
- "default": {
9
- "ENGINE": "django.db.backends.sqlite3",
10
- "NAME": ":memory:",
11
- }
12
- }
13
-
14
- INSTALLED_APPS = [
15
- "django.contrib.auth",
16
- "django.contrib.contenttypes",
17
- "django.contrib.sites",
18
- "django_json_widget",
19
- ]
20
-
21
- SITE_ID = 1
22
-
23
- MIDDLEWARE = ()