HttpRequestobject istance as well as instances of current user, forum, thread, post and post you are replying to. This pipeline then instiates classes defined in
PostingMiddlewareclass defined in
MISAGO_POSTING_MIDDLEWARESsetting is initialized and passed current context, which is then stored on its object attributes:
mode- Integer used to identify type of action. You can compare it with
EDITconstants defined in
request- HttpRequest using pipeline.
user- Authenticated user writing message.
category- Category in which message will be posted.
thread- Depending on
modeand phase in posting process, this may be thread loaded from database, or empty model that is yet to be saved in database.
post- Depending on
modeand phase in posting process, this may be post loaded from database, or empty model that is yet to be saved in database.
REPLY, this may be
Noneor instance of message to which reply is written by
datetime- Instance of
django.utils.timezone.nowcall. You can use it to avoid subtle differences betwen dates stored on different models generated by new calls to
parsing_result- dictionary containing result of parsing message entered by user.
use_this_middlewaremethod is called with no arguments to let middleware make decision if it wants to participate in process and return
Falseaccordingly. If you don't define this method yourself, default definition always returns
use_this_middlewaremethod mentioned ealier, each middleware may define following methods to participate in different phases of posting process:
legend- Name of form (eg. "Poll").
template- String with path to template that will be used to render this form.
is_supportingattribute with value being
js_templatemay be defined with path to template to be rendered before document's
Nonebefore any state was saved to database.
Noneto save state to database.
Noneto perform additional actions like sending notifications, etc. ect..
SaveChangesMiddlewaremiddleware that allows other middlewares to combine database saves. This middleware is called at the end of
post_savephrases, meaning its possible for other middlewares to delegate saves to it during any time of posting process.
savemethod with no arguments at the end of either
update_allflag at same time, Misago will perform one
save()call updating whole model.
update_fieldsis bad practice. If your middlware wants its changes saved to database, it should add changed fields names to
update_fieldslist even if it already contains them, or set
interrupt_postingphrase by raising
misago.threads.posting.PostingInterruptexception with error message as its only argument.
PostingInterrupts raised outside that phase will be escalated to
ValueErrorthat will result in 500 error response from Misago. However as this will happen inside database transaction, there is chance that no data loss has occured in the process.
contextdict with context that was passed to the posting middleware.
datadict with cleaned data:
postcontaining raw input entered by user and
parsing_result, an dict defining
parsed_textkey containing parsed message,
mentionswith list of mentions,
imageslist of urls to images and two lists:
internal_links. In case of user posting new thread, this dict will also contain
titlekey containing cleaned title.
from rest_framework.serializers.ValidationErroron error. If validation passes it may return nothing, or updated
datadict, which allows validators to perform last-minute cleanups on user input.