beat.web.ui.widgets module

beat.web.ui.widgets.uniq(seq, idfun=None)[source]

Order preserving, fast de-duplication for lists

beat.web.ui.widgets.isstring(obj)[source]
class beat.web.ui.widgets.CodeMirrorJavascript(js)[source]

Bases: object

An object used to mark Javascript sections in JSON output.

If an object of this type is passed to CodeMirrorJSONEncoder().encode(), the text containined in it will be output with no transformations applied. Most likely this will not be valid JSON, but it will be valid Javascript, assuming valid Javascript was passed to the constructor.

Example usage:

my_data = {

‘someKey’: True, ‘someCallback’: CodeMirrorJavascript(“function() { return true; }”)

}

CodeMirrorJSONEncoder().encode(my_data)

# -> ‘{“someKey”: true, “someCallback”: function() { return true; }}’

class beat.web.ui.widgets.CodeMirrorJSONEncoder(*args, **kwargs)[source]

Bases: json.encoder.JSONEncoder

A custom JSON encoder that knows how to handle CodeMirrorJavascript() objects.

stash_prefix = 'js_stash::'
default(obj)[source]

Implement this method in a subclass such that it returns a serializable object for o, or calls the base implementation (to raise a TypeError).

For example, to support arbitrary iterators, you could implement default like this:

def default(self, o):
    try:
        iterable = iter(o)
    except TypeError:
        pass
    else:
        return list(iterable)
    # Let the base class default method raise the TypeError
    return JSONEncoder.default(self, o)
encode(obj)[source]

Return a JSON string representation of a Python data structure.

>>> from json.encoder import JSONEncoder
>>> JSONEncoder().encode({"foo": ["bar", "baz"]})
'{"foo": ["bar", "baz"]}'
class beat.web.ui.widgets.FingerPrintedMedia(media=None, css=None, js=None)[source]

Bases: django.forms.widgets.Media

Subclass that adds version fingerprinting to the Media urls

absolute_path(path)[source]

Reimplementation to add version fingerprint to ensure file is served for the latest version of the application

class beat.web.ui.widgets.CodeMirrorTextarea(attrs=None, mode=None, theme=None, config=None, size=None, dependencies=(), addon_js=(), addon_css=(), custom_mode=None, custom_js=(), keymap=None, **kwargs)[source]

Bases: django.forms.widgets.Textarea

Textarea widget render with CodeMirror

CodeMirror: http://codemirror.net/

property media
render(name, value, attrs=None, renderer=None)[source]

Render CodeMirrorTextarea

class beat.web.ui.widgets.CodeMirrorFileWidget(*args, **kwargs)[source]

Bases: beat.web.ui.widgets.CodeMirrorTextarea

Allows editing a file instead of a plain content

property media
render(name, value, attrs=None, renderer=None)[source]

Render CodeMirrorTextarea