Form field widget

class djangocodemirror.widgets.CodeMirrorAdminWidget(*args, **kwargs)[source]

Bases: djangocodemirror.widgets.CodeMirrorWidget

CodeMirror widget suited for usage in models admins.

Act like CodeMirrorWidget but allways embed Codemirror Javascript config.

class djangocodemirror.widgets.CodeMirrorWidget(*args, **kwargs)[source]

Bases: django.forms.widgets.Textarea

Widget to add a CodeMirror or DjangoCodeMirror instance on a textarea Take the same arguments than forms.Textarea and accepts one suplementary optionnal arguments :

Parameters:
  • config_name (string) – A Codemirror config name available in settings.CODEMIRROR_SETTINGS. Default is empty.
  • embed_config (bool) – If True will add Codemirror Javascript config just below the input. Default is False.
config_name

string – For given config name.

codemirror_config()[source]

Shortcut to get Codemirror parameters.

Returns:CodeMirror parameters.
Return type:dict
codemirror_script(final_attrs)[source]

Build CodeMirror HTML script tag which contains CodeMirror init.

Parameters:final_attrs (dict) – Widget attributes that must contains the id attribute.
Returns:HTML for field CodeMirror instance.
Return type:string
get_codemirror_field_js()[source]

Return CodeMirror HTML template from CodeMirrorWidget.codemirror_field_js.

Returns:HTML template string.
Return type:string
init_manifest(name)[source]

Initialize a manifest instance

Parameters:name (string) – Config name to register.
Returns:A manifest instance where config (from config_name attribute) is registred.
Return type:CodeMirrorManifest
media

Adds necessary files (Js/CSS) to the widget’s medias.

Returns:Media object with all assets from registered config.
Return type:django.forms.Media
render(name, value, attrs=None)[source]

Render widget HTML

Parameters:
  • name (string) – Field input name.
  • value (string) – Field input value.
Keyword Arguments:
 

attrs (dict) – Optional field widget attributes. Default to None.

Returns:

Widget HTML representation.

Return type:

string