This hook allows plugins to replace or extend the standard logic used to validate post contents.
Post contents are represented as a ParsingResult object with the following attributes:
markup: str: The original markup posted by the user. -tokens: list[Token]: A token stream returned by the parser. -html: str: An HTML representation of the parsed markup. -text: str: A plain text representation of the parsed markup.
This hook can be imported from misago.posting.hooks:
from misago.posting.hooks import validate_post_hookdef custom_validate_post_filter(
action: ValidatePostHookAction,
value: ParsingResult,
min_length: int,
max_length: int,
request: HttpRequest | None=None,
) -> None:
...A function implemented by a plugin that can be registered in this hook.
The next function registered in this hook, either a custom function or Misago's default.
See the action section for details.
The value to validate.
The minimum required length of posted message.
The maximum allowed length of posted message. 0 disables this check.
The request object or None if not provided.
def validate_post_action(
value: ParsingResult,
min_length: int,
max_length: int,
request: HttpRequest | None=None,
) -> None:
...Misago function for validating the contents of a post. Raises ValidationError if the post contents are invalid.
The value to validate.
The minimum required length of posted message.
The maximum allowed length of posted message. 0 disables this check.
The request object or None if not provided.
Raises the minimal required length of a post for new users.
from django.http import HttpRequest
from misago.parser.parse import ParsingResult
from misago.posting.hooks import validate_post_hook
@validate_post_hook.append_filter
def validate_post_for_new_users(
action,
value: ParsingResult,
min_length: int,
max_length: int,
request: HttpRequest | None = None,
) -> None:
if request and request.user.is_authenticated and request.user.posts < 5:
min_length = min(min_length + 50)
action(value, min_length, max_length, request)