Skip to content

Latest commit

 

History

History
105 lines (62 loc) · 2.31 KB

File metadata and controls

105 lines (62 loc) · 2.31 KB

get_threads_page_subcategories_hook

This hook wraps the standard function that Misago uses to build a dict with data for the categories list component, used to display the list of subcategories on the threads page.

Location

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

from misago.threads.hooks import get_threads_page_subcategories_hook

Filter

def custom_get_threads_page_subcategories_filter(
    action: GetThreadsPageSubcategoriesHookAction, request: HttpRequest
) -> dict | None:
    ...

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

Arguments

action: GetThreadsPageSubcategoriesHookAction

Next function registered in this hook, either a custom function or Misago's standard one.

See the action section for details.

request: HttpRequest

The request object.

Return value

A Python dict with data for the categories list component.

Must have at least two keys: categories and template_name:

{
    "categories": ...,
    "template_name": "misago/thread_list/subcategories.html"
}

To suppress categories lists on a page, return None.

Action

def get_threads_page_subcategories_action(request: HttpRequest) -> dict | None:
    ...

Misago function used to build a dict with data for the categories list component, used to display the list of subcategories on the threads page.

Arguments

request: HttpRequest

The request object.

Return value

A Python dict with data for the categories list component.

Must have at least two keys: categories and template_name:

{
    "categories": ...,
    "template_name": "misago/category_thread_list/subcategories.html"
}

To suppress categories lists on a page, return None.

Example

The code below implements a custom filter function that replaces full subcategories component's template with a custom one

from django.http import HttpRequest
from misago.categories.models import Category
from misago.threads.hooks import get_threads_page_subcategories_hook


@get_threads_page_subcategories_hook.append_filter
def customize_subcategories_template(action, request: HttpRequest) -> dict | None:
    data = action(request)
    data["template_name"] = "plugin/subcategories.html"
    return data