This hook wraps a standard Misago function used to create a ThreadUpdate object.
This hook can be imported from misago.threadupdates.hooks:
from misago.threadupdates.hooks import create_thread_update_hookdef custom_create_thread_update_filter(
action: CreateThreadUpdateHookAction,
thread: 'Thread',
action_name: str,
actor: Union['User', None, str]=None,
*,
request: HttpRequest | None=None,
context: str | None=None,
context_object: Model | None=None,
is_hidden: bool=False,
plugin_data: dict,
) -> 'ThreadUpdate':
...A function implemented by a plugin that can be registered in this hook.
Misago function used to create a ThreadUpdate object.
A Thread instance.
A str with the name of the action that updated the thread.
A str with context, e.g., a previous thread title or the name of context_object. None if not available or not used for this action_name.
The request object or None if not available.
A str with context, e.g., a previous thread title or the name of context_object. None if not available or not used for this action_name.
A Model instance that this update object should store a generic relation to.
is_hidden: bool = False
Controls whether the newly created update should be hidden. Hidden updates are only visible to moderators but can be made visible to all users. Defaults to False.
A plugin data dict that will be saved on the ThreadUpdate.plugin_data attribute.
A newly created ThreadUpdate instance.
def create_thread_update_action(
thread: 'Thread',
action_name: str,
actor: Union['User', None, str]=None,
*,
request: HttpRequest | None=None,
context: str | None=None,
context_object: Model | None=None,
is_hidden: bool=False,
plugin_data: dict,
) -> 'ThreadUpdate':
...Misago function used to create a ThreadUpdate object.
A Thread instance.
A str with the name of the action that updated the thread.
The actor who performed the action: a User instance, a str with a name, or None if not available.
The request object or None if not available.
A str with context, e.g., a previous thread title or the name of context_object. None if not available or not used for this action_name.
A Model instance that this update object should store a generic relation to.
is_hidden: bool = False
Controls whether the newly created update should be hidden. Hidden updates are only visible to moderators but can be made visible to all users. Defaults to False.
A plugin data dict that will be saved on the ThreadUpdate.plugin_data attribute.
A newly created ThreadUpdate instance.
The code below implements a custom filter function that stores the actor's IP address on the update object:
from django.http import HttpRequest
from misago.threads.hooks import create_thread_update_hook
from misago.threads.models import Thread, ThreadUpdate
from misago.users.models import User
@create_thread_update_hook.append_filter
def set_actor_ip_on_thread_update(
action,
thread: "Thread",
action_name: str,
actor: Union["User", None, str] = None,
*,
request: HttpRequest | None = None,
context: str | None = None,
context_object: Model | None = None,
is_hidden: bool = False,
plugin_data: dict,
) -> ThreadUpdate:
if request:
plugin_data["actor_id"] = request.user_ip
return action(
thread,
action_name,
actor,
request=request,
context=context,
context_object=context_object,
is_hidden=is_hidden,
plugin_data=plugin_data,
)