Mixes in common logic for Markdown text fields.
Any resource implementing this is assumed to have at least one Markdown-capable text field.
Clients can pass
?force-text-type=(for GET) or
force_text_type=(for POST/PUT) with a value of
htmlto return the given text fields in the payload using the requested format.
markdownis specified, the Markdown text fields will return valid Markdown content, escaping if necessary.
plainis specified, plain text will be returned instead. If the content was in Markdown before, this will unescape the content.
htmlis specified, the content will be transformed into HTML suitable for display.
Clients can also pass
?include-text-types=<type1>[,<type2>,...](for GET) or
include_text_types=<type1>[,<type2>,...](for POST/PUT) to return the text fields within special
type_text_fieldsentries in the resource payload. A special type of “raw” is allowed, which will return the text types stored in the database.
(Note that passing
?include-text-types=rawis equivalent to passing
?include-raw-text-fields=1in 2.0.9 and 2.0.10. The latter is deprecated.)
TEXT_TYPES= (u’plain’, u’markdown’, u’html’)¶
SAVEABLE_TEXT_TYPES= (u’plain’, u’markdown’)¶
INCLUDEABLE_TEXT_TYPES= (u’plain’, u’markdown’, u’html’, u’raw’)¶
serialize_object(obj, *args, **kwargs)¶
Serializes the object, transforming text fields.
This is a specialization of serialize_object that transforms any text fields that support text types. It also handles attaching the raw text to the payload, on request.
serialize_text_type_field(obj, request=None, **kwargs)¶
Returns whether a particular field in extra_data can be imported.
If an extra_data field is marked as supporting rich text, we’ll skip importing it through normal means. Instead, it will be handled separately later.
Returns whether a particular field in extra_data supports Markdown.
If the field supports Markdown text, the value will be normalized based on the requested ?force-text-type= parameter.
set_text_fields(obj, text_field, rich_text_field_name=None, text_type_field_name=None, text_model_field=None, **kwargs)¶
Normalizes Markdown-capable text fields that are being saved.
set_extra_data_text_fields(obj, text_field, extra_fields, **kwargs)¶
Normalizes Markdown-capable text fields in extra_data.
This will check if any Markdown-capable text fields in extra_data have been changed (either by changing the text or the text type), and handle the saving of the text and type.
This works just like set_text_fields, but specially handles how things are stored in extra_data (text_type vs. rich_text fields, possible lack of presence of a text_type field, etc.).
A mixin for providing the ability to create and update using a form.
A WebAPIResource class using this mixin must set the
form_classattribute to a
ModelForminstance that corresponds to the model being updated.
Classes using this mixin can provide methods of the form
parse_<field_name>_fieldto do parsing of form data before it is passed to the form. These methods may return either a single value or a list (in the case where the corresponding field expects a list of values, such as a
save_form()methods should be used for creating new form instances and saving them. A form created this way can be given an optional instance argument to allow for updating the instance. Any fields missing from data (but appearing in the
fieldsattribute) will be copied over from the instance.
Save the form and extra data.
The saved model instance.