-
-
Notifications
You must be signed in to change notification settings - Fork 299
Expand file tree
/
Copy pathwidgets.py
More file actions
51 lines (46 loc) · 1.54 KB
/
Copy pathwidgets.py
File metadata and controls
51 lines (46 loc) · 1.54 KB
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
from django import forms
from django.contrib.admin.widgets import AdminTextareaWidget
from django.template.loader import get_template
from django.urls import reverse
class JsonSchemaWidget(AdminTextareaWidget):
"""
JSON Schema Editor widget
"""
schema_view_name = 'config:schema'
netjsonconfig_hint = True
extra_attrs = {}
advanced_mode = True
@property
def media(self):
js = [
f'config/js/{path}'
for path in (
'utils.js',
'lib/advanced-mode.js',
'lib/tomorrow_night_bright.js',
'lib/jsonschema-ui.js',
'widget.js',
)
]
css = {
'all': [
f'config/css/{path}'
for path in ('lib/jsonschema-ui.css', 'lib/advanced-mode.css')
]
}
return forms.Media(js=js, css=css)
def render(self, name, value, attrs=None, renderer=None):
template = get_template('admin/config/jsonschema-widget.html')
html = template.render(
{
'schema_view_name': self.schema_view_name,
'netjsonconfig_hint': self.netjsonconfig_hint,
'advanced_mode': self.advanced_mode,
}
)
attrs = attrs or {}
attrs['class'] = 'vLargeTextField jsoneditor-raw'
attrs.update(self.extra_attrs)
attrs.update({'data-schema-url': reverse(self.schema_view_name)})
html += super().render(name, value, attrs, renderer)
return html