This hook wraps a standard Misago function used to hide a PostEdit object.
This hook can be imported from misago.edits.hooks:
from misago.edits.hooks import hide_post_edit_hookdef custom_hide_post_edit_filter(
action: HidePostEditHookAction,
post_edit: 'PostEdit',
user: Union['User', str],
commit: bool=True,
request: HttpRequest | 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.
A PostEdit instance to hide.
The user who hid the edit, a User instance or a str with the user's name.
A bool indicating whether the updated PostEdit instance should be saved to the database.
Defaults to True.
The request object or None if not available.
def hide_post_edit_action(
post_edit: 'PostEdit',
user: Union['User', str],
commit: bool=True,
request: HttpRequest | None=None,
):
...Misago function used to hide a PostEdit object.
A PostEdit instance to hide.
The user who hid the edit, a User instance or a str with the user's name.
A bool indicating whether the updated PostEdit instance should be saved to the database.
Defaults to True.
The request object or None if not available.
The code below implements a custom filter function that records the user's IP address:
from django.http import HttpRequest
from misago.edits.hooks import hide_post_edit_hook
from misago.edits.models import PostEdit
from misago.users.models import User
@hide_post_edit_hook.append_filter
def hide_post_edit_record_user_ip(
action,
post_edit: PostEdit,
user: User | str,
commit: bool = True,
request: HttpRequest | None = None,
):
action(post_edit, user, False, request)
if request:
post_edit.plugin_data["hidden_by_ip"] = request.user_ip
if commit:
post_edit.save()