• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

rafalp / Misago / 15760443583

19 Jun 2025 02:37PM UTC coverage: 97.274% (+0.06%) from 97.214%
15760443583

push

github

web-flow
Replace thread events with updates (#1944)

2828 of 2914 new or added lines in 89 files covered. (97.05%)

27 existing lines in 5 files now uncovered.

74115 of 76192 relevant lines covered (97.27%)

0.97 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.86
/misago/threadupdates/hooks/unhide_thread_update.py
1
from typing import TYPE_CHECKING, Protocol
1✔
2

3
from django.http import HttpRequest
1✔
4

5
from ...plugins.hooks import FilterHook
1✔
6

7
if TYPE_CHECKING:
1✔
NEW
8
    from ..models import ThreadUpdate
×
9

10

11
class UnhideThreadUpdateHookAction(Protocol):
1✔
12
    """
13
    A standard Misago function used to unhide a `ThreadUpdate` object.
14

15
    # Arguments
16

17
    ## `thread_update: ThreadUpdate`
18

19
    A `ThreadUpdate` instance to unhide.
20

21
    ## `update_fields: set[str]`
22

23
    A `set` of `str` containing the names of fields to pass to the `update(update_fields=...)` option.
24

25
    ## `request: HttpRequest | None = None`
26

27
    The request object or `None` if not available.
28

29
    # Return value
30

31
    `True` if the thread update was unhidden, `False` otherwise.
32
    """
33

34
    def __call__(
1✔
35
        self,
36
        thread_update: "ThreadUpdate",
37
        update_fields: set[str],
38
        request: HttpRequest | None = None,
39
    ) -> bool: ...
40

41

42
class UnhideThreadUpdateHookFilter(Protocol):
1✔
43
    """
44
    A function implemented by a plugin that can be registered in this hook.
45

46
    # Arguments
47

48
    ## `action: UnhideThreadUpdateHookAction`
49

50
    A standard Misago function used to unhide a `ThreadUpdate` object.
51

52
    ## `thread_update: ThreadUpdate`
53

54
    A `ThreadUpdate` instance to unhide.
55

56
    ## `update_fields: set[str]`
57

58
    A `set` of `str` containing the names of fields to pass to the `update(update_fields=...)` option.
59

60
    ## `request: HttpRequest | None = None`
61

62
    The request object or `None` if not available.
63

64
    # Return value
65

66
    `True` if the thread update was unhidden, `False` otherwise.
67
    """
68

69
    def __call__(
1✔
70
        self,
71
        action: UnhideThreadUpdateHookAction,
72
        thread_update: "ThreadUpdate",
73
        update_fields: set[str],
74
        request: HttpRequest | None = None,
75
    ) -> bool: ...
76

77

78
class UnhideThreadUpdateHook(
1✔
79
    FilterHook[
80
        UnhideThreadUpdateHookAction,
81
        UnhideThreadUpdateHookFilter,
82
    ]
83
):
84
    """
85
    This hook wraps a standard Misago function used to unhide a `ThreadUpdate` object.
86

87
    # Example
88

89
    The code below implements a custom filter function that stores the client's
90
    IP address when a thread update is unhidden:
91

92
    ```python
93
    from django.http import HttpRequest
94
    from misago.threads.hooks import unhide_thread_update_hook
95
    from misago.threads.models import ThreadUpdate
96

97

98
    @unhide_thread_update_hook.append_filter
99
    def save_client_ip_on_thread_update_unhide(
100
        action,
101
        thread_update: ThreadUpdate,
102
        update_fields: set[str],
103
        request: HttpRequest | None = None,
104
    ) -> bool:
105
        if not request:
106
            return action(thread_update, update_fields)
107

108
        thread_update.plugin_data["last_ip"] = request.client_ip
109
        update_fields.add("plugin_data")
110

111
        return action(thread_update, update_fields, request)
112
    ```
113
    """
114

115
    __slots__ = FilterHook.__slots__
1✔
116

117
    def __call__(
1✔
118
        self,
119
        action: UnhideThreadUpdateHookAction,
120
        thread_update: "ThreadUpdate",
121
        update_fields: set[str],
122
        request: HttpRequest | None = None,
123
    ) -> "ThreadUpdate":
124
        return super().__call__(
1✔
125
            action,
126
            thread_update,
127
            update_fields,
128
            request,
129
        )
130

131

132
unhide_thread_update_hook = UnhideThreadUpdateHook()
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc