reviewboard.webapi.mixins¶
-
class
MarkdownFieldsMixin
[source]¶ Bases:
object
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) orforce_text_type=
(for POST/PUT) with a value ofplain
,markdown
orhtml
to return the given text fields in the payload using the requested format.When
markdown
is specified, the Markdown text fields will return valid Markdown content, escaping if necessary.When
plain
is specified, plain text will be returned instead. If the content was in Markdown before, this will unescape the content.When
html
is specified, the content will be transformed into HTML suitable for display.Clients can also pass
?include-text-types=<type1>[,<type2>,...]
(for GET) orinclude_text_types=<type1>[,<type2>,...]
(for POST/PUT) to return the text fields within specialtype_text_fields
entries 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=raw
is equivalent to passing?include-raw-text-fields=1
in 2.0.9 and 2.0.10. The latter is deprecated.)-
serialize_object
(obj, *args, **kwargs)[source]¶ 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.
-
can_import_extra_data_field
(obj, field)[source]¶ 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.
-
get_extra_data_field_supports_markdown
(obj, key)[source]¶ 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)[source]¶ Normalizes Markdown-capable text fields that are being saved.
-
set_extra_data_text_fields
(obj, text_field, extra_fields, **kwargs)[source]¶ 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.).
-
-
class
UpdateFormMixin
[source]¶ Bases:
djblets.webapi.resources.mixins.forms.UpdateFormMixin
A mixin for providing the ability to create and update using a form.
A WebAPIResource class using this mixin must set the
form_class
attribute to aModelForm
instance that corresponds to the model being updated.Classes using this mixin can provide methods of the form
parse_<field_name>_field
to 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 adjango.forms.ModelMultipleChoiceField
).The
create_form()
andsave_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 theform_class
’sfields
attribute) will be copied over from the instance.-
save_form
(form, extra_fields=None)[source]¶ Save the form and extra data.
Parameters: - form (django.forms.ModelForm) – The form to save.
- extra_fields (dict) – The extra data to save on the object. These should be key-value
pairs in the form of
extra_data.key = value
.
Returns: The saved model instance.
Return type:
-