This hook allows plugins to replace or extend the logic used to move threads to a new category.
This hook can be imported from misago.threads.hooks:
from misago.threads.hooks import move_threads_hookdef custom_move_threads_filter(
action: MoveThreadsHookAction,
threads: Iterable[Thread],
new_category: Category,
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 iterable of threads to move.
A Category to move threads to.
Whether the threads' category field should be updated directly in the database using QuerySet.update().
When True, only the category column is saved. If other fields need updating, set this to False and handle updates manually.
Defaults to True.
The request object, or None if not provided.
def move_threads_action(
threads: Iterable[Thread],
new_category: Category,
commit: bool=True,
request: HttpRequest | None=None,
) -> None:
...Misago function for moving threads to a new category.
The iterable of threads to move.
A Category to move threads to.
Whether the threads' category field should be updated directly in the database using QuerySet.update().
When True, only the category column is saved. If other fields need updating, set this to False and handle updates manually.
Defaults to True.
The request object, or None if not provided.
Update category attribute on plugin model:
from typing import Iterable
from django.http import HttpRequest
from misago.categories.models import Category
from misago.threads.hooks import move_threads_hook
from misago.threads.models import Thread
from .models import PluginModel
@move_threads_hook.append_filter
def move_plugin_models_to_new_category(
action,
threads: Iterable[Thread],
new_category: Category,
commit: bool = True,
request: HttpRequest | None = None,
):
action(thread, data, commit, request)
PluginModel.objects.filter(
thread__in=threads
).update(category=new_category)