This hook wraps the standard function that Misago uses to save a new thread to the database.
This hook can be imported from misago.posting.hooks:
from misago.posting.hooks import save_thread_start_state_hookdef custom_save_thread_start_state_filter(
action: SaveThreadStartStateHookAction,
request: HttpRequest,
state: '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 ThreadStartState object that stores all data to save to the database.
def save_thread_start_state_action(request: HttpRequest, state: 'ThreadStartState'):
...A standard function that Misago uses to save a new thread to the database.
The request object.
The ThreadStartState object that stores all data to save to the database.
The code below implements a custom filter function that stores the user's IP on the saved thread and post.
from django.http import HttpRequest
from misago.posting.hooks import save_thread_start_state_hook
from misago.posting.state.start import ThreadStartState
@save_thread_start_state_hook.append_filter
def save_poster_ip_on_started_thread(
action, request: HttpRequest, state: ThreadStartState
):
state.thread.plugin_data["starter_ip"] = request.user_ip
state.post.plugin_data["poster_ip"] = request.user_ip
action(request, state)