This hook allows plugins to replace or extend the logic used to set a post as the thread’s solution.
This hook can be imported from misago.solutions.hooks:
from misago.solutions.hooks import set_thread_solution_hookdef custom_set_thread_solution_filter(
action: SetThreadSolutionHookAction,
thread: Thread,
post: Post,
user: Union['User', str],
commit: bool=True,
request: HttpRequest | None=None,
) -> None:
...A function implemented by a plugin that can be registered in this hook.
Next function registered in this hook, either a custom function or Misago's standard one.
See the action section for details.
The thread to update.
The post to set as the solution.
The user who selected the solution.
Whether the updated thread instance should be saved to the database.
Defaults to True.
The request object, or None if not provided.
def set_thread_solution_action(
thread: Thread,
post: Post,
user: Union['User', str],
commit: bool=True,
request: HttpRequest | None=None,
) -> None:
...Misago function for setting a post as the thread’s solution.
The thread to update.
The post to set as the solution.
The user who selected the solution.
Whether the updated thread instance should be saved to the database.
Defaults to True.
The request object, or None if not provided.
Record the IP address of the user who selected the solution:
from django.http import HttpRequest
from misago.solutions.hooks import set_thread_solution_hook
from misago.threads.models import Thread, Post
from misago.users.models import User
@set_thread_solution_hook.append_filter
def record_solution_user_ip_address(
action,
thread: Thread,
post: Post,
user: User | str,
commit: bool = True,
request: HttpRequest | None = None,
) -> None:
action(thread, post, user, False, request)
if request:
thread.plugin_data["solution_user_ip"] = request.user_ip
if commit:
thread.save()