kopia lustrzana https://github.com/wagtail/wagtail
Allow different registries to be created for different object types
rodzic
8a80196456
commit
f2f6167f5d
|
|
@ -8,8 +8,10 @@ class LogActionRegistry:
|
|||
A central store for log actions.
|
||||
The expected format for registered log actions: Namespaced action, Action label, Action message (or callable)
|
||||
"""
|
||||
def __init__(self):
|
||||
# Has the register_log_actions hook been run for this registry?
|
||||
def __init__(self, hook_name):
|
||||
self.hook_name = hook_name
|
||||
|
||||
# Has the hook been run for this registry?
|
||||
self.has_scanned_for_actions = False
|
||||
|
||||
# Holds the actions.
|
||||
|
|
@ -23,7 +25,7 @@ class LogActionRegistry:
|
|||
|
||||
def scan_for_actions(self):
|
||||
if not self.has_scanned_for_actions:
|
||||
for fn in hooks.get_hooks('register_log_actions'):
|
||||
for fn in hooks.get_hooks(self.hook_name):
|
||||
fn(self)
|
||||
|
||||
self.has_scanned_for_actions = True
|
||||
|
|
@ -57,4 +59,5 @@ class LogActionRegistry:
|
|||
return self.get_actions()[action][0]
|
||||
|
||||
|
||||
page_log_action_registry = LogActionRegistry()
|
||||
# For historical reasons, pages use the 'register_log_actions' hook
|
||||
page_log_action_registry = LogActionRegistry('register_log_actions')
|
||||
|
|
|
|||
|
|
@ -321,19 +321,19 @@ class TestAuditLogHooks(TestCase, WagtailTestUtils):
|
|||
def test_register_log_actions_hook(self):
|
||||
# testapp/wagtail_hooks.py defines a 'blockquote' rich text feature with a hallo.js
|
||||
# plugin, via the register_rich_text_features hook; test that we can retrieve it here
|
||||
log_actions = LogActionRegistry()
|
||||
log_actions = LogActionRegistry('register_log_actions')
|
||||
actions = log_actions.get_actions()
|
||||
self.assertIn('wagtail.create', actions)
|
||||
|
||||
def test_action_format_message(self):
|
||||
log_entry = PageLogEntry.objects.log_action(self.root_page, action='test.custom_action')
|
||||
|
||||
log_actions = LogActionRegistry()
|
||||
log_actions = LogActionRegistry('register_log_actions')
|
||||
self.assertEqual(log_actions.format_message(log_entry), "Unknown test.custom_action")
|
||||
self.assertNotIn('test.custom_action', log_actions.get_actions())
|
||||
|
||||
with self.register_hook('register_log_actions', test_hook):
|
||||
log_actions = LogActionRegistry()
|
||||
log_actions = LogActionRegistry('register_log_actions')
|
||||
self.assertIn('test.custom_action', log_actions.get_actions())
|
||||
self.assertEqual(log_actions.format_message(log_entry), "Tested!")
|
||||
self.assertEqual(log_actions.get_action_label('test.custom_action'), 'Custom action')
|
||||
|
|
|
|||
Ładowanie…
Reference in New Issue