HttpRequest
object istance as well as instances of current user, forum, thread, post and post you are replying to. This pipeline then instiates classes defined in MISAGO_POSTING_MIDDLEWARES
setting.PostingMiddleware
class defined in misago.threads.posting
package.MISAGO_POSTING_MIDDLEWARES
setting 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 START
, REPLY
and EDIT
constants defined in misago.threads.posting
package.request
- HttpRequest using pipeline.user
- Authenticated user writing message.category
- Category in which message will be posted.thread
- Depending on mode
and 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 mode
and phase in posting process, this may be post loaded from database, or empty model that is yet to be saved in database.quote
- If mode
is REPLY
, this may be None
or instance of message to which reply is written by user
.datetime
- Instance of datetime
returned by django.utils.timezone.now
call. You can use it to avoid subtle differences betwen dates stored on different models generated by new calls to timezone.now
.parsing_result
- dictionary containing result of parsing message entered by user.use_this_middleware
method is called with no arguments to let middleware make decision if it wants to participate in process and return True
or False
accordingly. If you don't define this method yourself, default definition always returns True
.use_this_middleware
method mentioned ealier, each middleware may define following methods to participate in different phases of posting process:make_form()
legend
- Name of form (eg. "Poll").template
- String with path to template that will be used to render this form.is_main
or is_supporting
attribute with value being True
.js_template
may be defined with path to template to be rendered before document's </body>
.pre_save(form)
None
before any state was saved to database.save(form)
None
to save state to database.post_save(form)
None
to perform additional actions like sending notifications, etc. ect..SaveChangesMiddleware
middleware that allows other middlewares to combine database saves. This middleware is called at the end of save
and post_save
phrases, meaning its possible for other middlewares to delegate saves to it during any time of posting process.User
, Forum
, Thread
and Post
models: update_all
and update_fields
.update_all
attribute to True
will make SaveChangesMiddleware
call model's save
method with no arguments at the end of either save
or post_save
phase.update_fields
attribute instead.update_fields
and set update_all
flag at same time, Misago will perform one save()
call updating whole model.update_all
or update_fields
is bad practice. If your middlware wants its changes saved to database, it should add changed fields names to update_fields
list even if it already contains them, or set update_all
to True
.interrupt_posting
phrase by raising misago.threads.posting.PostingInterrupt
exception with error message as its only argument.PostingInterrupt
s raised outside that phase will be escalated to ValueError
that 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.MISAGO_POST_VALIDATORS
settings.context
dict with context that was passed to the posting middleware.data
dict with cleaned data: post
containing raw input entered by user and parsing_result
, an dict defining parsed_text
key containing parsed message, mentions
with list of mentions, images
list of urls to images and two lists: outgoing_links
and internal_links
. In case of user posting new thread, this dict will also contain title
key containing cleaned title.from rest_framework.serializers.ValidationError
on error. If validation passes it may return nothing, or updated data
dict, which allows validators to perform last-minute cleanups on user input.