9
9
class JSONEditorWidget (forms .Widget ):
10
10
template_name = 'django_admin_json_editor/editor.html'
11
11
12
- def __init__ (self , schema , collapsed = True , sceditor = False , schema_choices = False , schema_choice_field_name = False ):
12
+ def __init__ (self , schema , collapsed = True , sceditor = False , schema_choices = False , schema_choice_field_name = False , default_options = False ):
13
13
super (JSONEditorWidget , self ).__init__ ()
14
14
self ._schema = schema
15
15
self ._collapsed = collapsed
16
16
self ._sceditor = sceditor
17
17
self ._schema_choices = schema_choices
18
18
self ._schema_choice_field_name = schema_choice_field_name
19
+ self ._default_options = default_options if default_options else {}
19
20
20
21
if schema_choices and schema_choice_field_name :
21
22
if type (schema_choices ) != dict :
@@ -25,6 +26,9 @@ def __init__(self, schema, collapsed=True, sceditor=False, schema_choices=False,
25
26
elif (schema_choices and not schema_choice_field_name ) or (schema_choice_field_name and not schema_choices ):
26
27
raise AttributeError ("schema_choices and schema_choice_field_name must be supplied together." )
27
28
29
+ if default_options and type (default_options ) != dict :
30
+ raise TypeError ("default_options must be a dict, but type of \" %s\" was given" % type (default_options ))
31
+
28
32
def render (self , name , value , attrs = None , renderer = None ):
29
33
if callable (self ._schema ):
30
34
schema = self ._schema (self )
@@ -51,7 +55,8 @@ def render(self, name, value, attrs=None, renderer=None):
51
55
'data' : value ,
52
56
'sceditor' : int (self ._sceditor ),
53
57
'schema_choices' : schema_choices ,
54
- 'schema_choice_field_name' : self ._schema_choice_field_name
58
+ 'schema_choice_field_name' : self ._schema_choice_field_name ,
59
+ 'default_options' : self ._default_options
55
60
}
56
61
return mark_safe (render_to_string (self .template_name , context ))
57
62
0 commit comments