This hook wraps the standard function Misago uses to create a new ThreadStartState instance for starting a new thread.
This hook can be imported from misago.posting.hooks:
from misago.posting.hooks import get_thread_start_state_hookdef custom_get_thread_start_state_filter(
action: GetThreadStartStateHookAction,
request: HttpRequest,
category: Category,
) -> 'ThreadStartState':
...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 request object.
The Category instance.
A ThreadStartState instance to use to create a new thread in the database.
def get_thread_start_state_action(request: HttpRequest, category: Category) -> 'ThreadStartState':
...A standard function that Misago uses to create a new ThreadStartState instance for starting a new thread.
The request object.
The Category instance.
A ThreadStartState instance to use to create a new thread in the database.
The code below implements a custom filter function that stores the user's IP in the state.
from django.http import HttpRequest
from misago.categories.models import Category
from misago.posting.hooks import get_thread_start_state_hook
from misago.posting.state import ThreadStartState
@get_thread_start_state_hook.append_filter
def set_poster_ip_on_start_thread_state(
action, request: HttpRequest, category: Category
) -> ThreadStartState:
state = action(request, category)
state.plugin_state["user_id"] = request.user_ip
return state