This hook wraps the standard function that Misago uses to create a new ThreadReplyFormset instance with forms for posting a new thread reply.
This hook can be imported from misago.posting.hooks:
from misago.posting.hooks import get_thread_reply_formset_hookdef custom_get_thread_reply_formset_filter(
action: GetThreadReplyFormsetHookAction,
request: HttpRequest,
thread: Thread,
initial: dict | None,
) -> 'ThreadReplyFormset':
...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 Thread instance.
A dict containing initial data, or None.
A ThreadReplyFormset instance with forms for posting a new thread reply.
def get_thread_reply_formset_action(
request: HttpRequest, thread: Thread, initial: dict | None
) -> 'ThreadReplyFormset':
...A standard function that Misago uses to create a new ThreadReplyFormset instance with forms for posting a new thread reply.
The request object.
The Thread instance.
A dict containing initial data, or None.
A ThreadReplyFormset instance with forms for posting a new thread reply.
The code below implements a custom filter function that adds custom form to the new thread reply formset:
from django.http import HttpRequest
from misago.posting.formsets import ThreadReplyFormset
from misago.posting.hooks import get_thread_reply_formset_hook
from misago.threads.models import Thread
from .forms import SelectUserForm
@get_thread_reply_formset_hook.append_filter
def add_select_user_form(
action, request: HttpRequest, thread: Thread, initial: dict | None
) -> ThreadReplyFormset:
formset = action(request, thread, initial)
if request.method == "POST":
form = SelectUserForm(request.POST, prefix="select-user")
else:
form = SelectUserForm(prefix="select-user")
formset.add_form(form, before="posting-post")
return formset