Skip to content

Latest commit

 

History

History
114 lines (65 loc) · 2.21 KB

File metadata and controls

114 lines (65 loc) · 2.21 KB

get_thread_reply_state_hook

This hook wraps the standard function Misago uses to create a new ThreadReplyState instance for the thread reply view.

Location

This hook can be imported from misago.posting.hooks:

from misago.posting.hooks import get_thread_reply_state_hook

Filter

def custom_get_thread_reply_state_filter(
    action: GetThreadReplyStateHookAction,
    request: HttpRequest,
    thread: Thread,
    post: Post | None=None,
) -> 'ThreadReplyState':
    ...

A function implemented by a plugin that can be registered in this hook.

Arguments

action: GetThreadReplyStateHookAction

The next function registered in this hook, either a custom function or Misago's default.

See the action section for details.

request: HttpRequest

The request object.

thread: Thread

The Thread instance.

post: Post | None

The Post instance to append posted contents to, or None.

Return value

A ThreadReplyState instance to use to create a reply in a thread in the database.

Action

def get_thread_reply_state_action(
    request: HttpRequest, thread: Thread, post: Post | None=None
) -> 'ThreadReplyState':
    ...

Misago function used to create a new ThreadReplyState instance for the thread reply view.

Arguments

request: HttpRequest

The request object.

thread: Thread

The Thread instance.

post: Post | None

The Post instance to append posted contents to, or None.

Return value

A ThreadReplyState instance to use to create a reply in a thread in the database.

Example

The code below implements a custom filter function that stores the user's IP in the state.

from django.http import HttpRequest
from misago.posting.hooks import get_thread_reply_state_hook
from misago.posting.state import ThreadReplyState
from misago.threads.models import Post, Thread


@get_thread_reply_state_hook.append_filter
def set_poster_ip_on_reply_thread_state(
    action,
    request: HttpRequest,
    thread: Thread,
    post: Post | None = None,
) -> ThreadReplyState:
    state = action(request, thread)
    state.plugin_state["user_id"] = request.user_ip
    return state