Example #1
0
def plaintext(content, object):
    """
    This template filter takes a string value and passes it through the
    function specified by the RICHTEXT_PLAIN_FILTER setting.
    """
    richtext_filter = getattr(settings, "RICHTEXT_FILTER", None)
    richtext_plain_filter = getattr(settings, "RICHTEXT_PLAIN_FILTER", None)
    if richtext_plain_filter:
        func = import_dotted_path(richtext_plain_filter)
    elif richtext_filter:
        f = import_dotted_path(richtext_filter)
        func = lambda s, o: unescape(strip_tags(f(s, o)))
    else:
        func = lambda s, o: s
    return func(content, object)
Example #2
0
def plaintext(content, object):
    """
    This template filter takes a string value and passes it through the
    function specified by the RICHTEXT_PLAIN_FILTER setting.
    """
    richtext_filter = getattr(settings, "RICHTEXT_FILTER", None)
    richtext_plain_filter = getattr(settings, "RICHTEXT_PLAIN_FILTER", None)
    if richtext_plain_filter:
        func = import_dotted_path(richtext_plain_filter)
    elif richtext_filter:
        f = import_dotted_path(richtext_filter)
        func = lambda s, o: unescape(strip_tags(f(s, o)))
    else:
        func = lambda s, o: s
    return func(content, object)
Example #3
0
def richtext(content, object):
    """
    This template filter takes a string value and passes it through the
    function specified by the RICHTEXT_FILTER setting.
    """
    richtext_filter = getattr(settings, "RICHTEXT_FILTER", None)
    if richtext_filter:
        func = import_dotted_path(richtext_filter)
    else:
        func = lambda s, o: mark_safe(linebreaks(s, True))
    return func(content, object)
Example #4
0
def richtext(content, object):
    """
    This template filter takes a string value and passes it through the
    function specified by the RICHTEXT_FILTER setting.
    """
    richtext_filter = getattr(settings, "RICHTEXT_FILTER", None)
    if richtext_filter:
        func = import_dotted_path(richtext_filter)
    else:
        func = lambda s, o: mark_safe(linebreaks(s, True))
    return func(content, object)
Example #5
0
def enhance_fields(form, cls):
    """
    Replaces textinputs field of *form* with auto complete fields.

    Replaces textareas' widgets with widgets user defined widgets
    (:setting:`RICHTEXT_WIDGET_CLASS` setting).

    :param form: a :class:`Form` instance or class
    :param cls: class of the source that provides suggested values
    """
    richtext_class = getattr(settings, "RICHTEXT_WIDGET_CLASS", None)
    if richtext_class is not None:
        richtext_class = import_dotted_path(richtext_class)

    for field, form_field in form.base_fields.iteritems():
        if field not in ("reference", "revision") and \
                isinstance(form_field.widget, forms.TextInput):
            source = '/ajax/complete/%s/%s/' % (cls.__name__, field)
            form_field.widget = JQueryAutoComplete(source)
        elif (richtext_class is not None and
              isinstance(form_field.widget, forms.Textarea)):
            f = cls._meta.get_field(field)
            if getattr(f, "richtext", False):
                form_field.widget = richtext_class()
Example #6
0
def enhance_fields(form, cls):
    """
    Replaces textinputs field of *form* with auto complete fields.

    Replaces textareas' widgets with widgets user defined widgets
    (:setting:`RICHTEXT_WIDGET_CLASS` setting).

    :param form: a :class:`Form` instance or class
    :param cls: class of the source that provides suggested values
    """
    richtext_class = getattr(settings, "RICHTEXT_WIDGET_CLASS", None)
    if richtext_class is not None:
        richtext_class = import_dotted_path(richtext_class)

    for field, form_field in form.base_fields.iteritems():
        if field not in ("reference", "revision") and \
                isinstance(form_field.widget, forms.TextInput):
            source = '/ajax/complete/%s/%s/' % (cls.__name__, field)
            form_field.widget = JQueryAutoComplete(source)
        elif (richtext_class is not None
              and isinstance(form_field.widget, forms.Textarea)):
            f = cls._meta.get_field(field)
            if getattr(f, "richtext", False):
                form_field.widget = richtext_class()
Example #7
0
def get_form():
    widget_class = getattr(settings, "RICHTEXT_WIDGET_CLASS", None)
    if widget_class is not None:
        cls = import_dotted_path(widget_class)
        CommentForm.base_fields["comment"].widget = cls()
    return CommentForm
Example #8
0
def get_form():
    widget_class = getattr(settings, "RICHTEXT_WIDGET_CLASS", None)
    if widget_class is not None:
        cls = import_dotted_path(widget_class)
        CommentForm.base_fields["comment"].widget = cls()
    return CommentForm