This hook wraps the function Misago uses to get the template context data for the thread edit view.
This hook can be imported from misago.posting.hooks:
from misago.posting.hooks import get_thread_edit_context_data_hookdef custom_get_thread_edit_context_data_filter(
action: GetThreadEditContextDataHookAction,
request: HttpRequest,
post: Post,
formset: 'EditThreadFormset',
) -> dict:
...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 Post instance.
The EditThreadFormset instance.
A Python dict with context data used to render the thread edit view.
def get_thread_edit_context_data_action(
request: HttpRequest, post: Post, formset: 'EditThreadFormset'
) -> dict:
...Misago function used to get the template context data for the thread edit view.
The request object.
The Post instance.
The EditThreadFormset instance.
A Python dict with context data used to render the thread edit view.
The code below implements a custom filter function that adds extra values to the template context data:
from django.http import HttpRequest
from misago.posting.formsets import EditThreadFormset
from misago.posting.hooks import get_thread_edit_context_data_hook
from misago.threads.models import Post
@get_thread_edit_context_data_hook.append_filter
def set_show_first_post_warning_in_context(
action,
request: HttpRequest,
post: Post,
formset: EditThreadFormset,
) -> dict:
context = action(request, thread, formset)
context["show_first_post_warning"] = request.user.posts == 1
return context