Coverage for markupmirror.fields : 98%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# suffixes for rendered and markup_type fields
"""Wrapper class for markup content output.
Stores the names of the associated field, the rendered field and the markup_type field to make assignment possible.
When accessing the value of a ``MarkupField``, a ``Markup`` instance will be returned. This provides a few methods to access the raw and rendered markup, and the markup type of the saved content.
""" rendered_field_name, markup_type_field_name):
def raw(self): """The raw markup content."""
def raw(self, value):
def markup_type(self): """Markup type of the current markup content."""
def markup_type(self, value):
def rendered(self): """Returns the rendered markup content (read only). This is only available after ``Model.save`` has been called.
"""
"""Allows display via templates to work without safe filter. Same as ``rendered``.
"""
"""Descriptor class for field functionality."""
self.rendered_field_name, self.markup_type_field_name)
else:
"""Field to store markup content.
The ``MarkupMirrorField`` adds three fields to the model it is used in.
* One field for the raw markup content (``<field_name>``). * One field for the rendered HTML content (``<field_name>_rendered``). * One field that specifies the markup type (``<field_name>_markup_type``).
The field can be used with a fixed ``markup_type`` or a ``default_markup_type``, which displays an additional selection widget for the available markup types. However, only one of ``markup_type`` and ``default_markup_type`` can be provided.
If neither is provided, the setting ``MARKUPMIRROR_DEFAULT_MARKUP_TYPE`` is used as ``default_markup_type`` instead.
""" markup_type=None, default_markup_type=None, escape_html=False, **kwargs): "Cannot specify both markup_type and default_markup_type")
self.default_markup_type not in markup_pool): "Invalid default_markup_type for field '%r', " "available types: %s" % ( name or verbose_name, ', '.join(sorted(markup_pool.markups.keys()))))
# for South FakeORM compatibility: the frozen version of a # MarkupMirrorField can't try to add a _rendered field, because the # _rendered field itself is frozen as well. See introspection # rules below.
"""Adds two additional fields for rendered HTML content and markup type to the model.
""" # markup_type sorted(markup_pool.markups.iteritems(), key=lambda markup: markup[1].title.lower())] choices=choices, max_length=30, default=self.default_markup_type, blank=self.blank, editable=self.markup_type_editable)
# rendered editable=False, blank=True, null=True)
# add fields to class
# use MarkupMirrorFieldDescriptor to access this field
# check for valid markup type 'Invalid markup type (%s), available types: %s' % ( value.markup_type, ', '.join(sorted(markup_pool.markups.keys()))))
# escape HTML else:
else:
"""Adds attributes necessary for CodeMirror initialization to the field's widget.
The class "markupmirror-editor" is used to identify textareas that should be enhanced with the editor.
The ``data-mode`` and ``data-markuptype`` attributes depend on a selected ``default_markup_type``. If a field does not have a default markup type selected, the attributes will be added in the widgets' ``render`` method by accessing the ``markup_type`` property of the markup content wrapper ``markupmirror.fields.Markup``.
""" 'class': 'markupmirror-editor', } self.default_markup_type in markup_pool): # prepare default settings for CodeMirror and preview in case # the widget has no value yet. 'mode': markup_pool[self.default_markup_type].codemirror_mode, 'markup_type': self.default_markup_type, } sort_keys=True)
'widget': widgets.MarkupMirrorTextarea(attrs=widget_attrs), }
# register MarkupMirrorField to use the custom widget in the Admin
'widget': widgets.AdminMarkupMirrorTextareaWidget, }
# allow South to handle MarkupMirrorField smoothly # For a normal MarkupMirrorField, the add_rendered_field attribute is # always True, which means no_rendered_field arg will always be # True in a frozen MarkupMirrorField, which is what we want. rules=[ ((MarkupMirrorField,), [], { 'rendered_field': ['rendered_field', {}], }) ], patterns=['markupmirror\.fields\.MarkupMirrorField']) except ImportError: pass |