annotate MoinMoin/events/__init__.py @ 2633:f42fb1ae0a38

Fixes to the Event.name commit.
author Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
date Thu, 26 Jul 2007 04:05:21 +0200
parents 35690680ecac
children 6e84127a1860
rev   line source
2058
fb6f1de06be0 Start with a simplistic event handling system, which uses plugins in a way
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
fb6f1de06be0 Start with a simplistic event handling system, which uses plugins in a way
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
2 """
fb6f1de06be0 Start with a simplistic event handling system, which uses plugins in a way
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
3 MoinMoin - event (notification) framework
fb6f1de06be0 Start with a simplistic event handling system, which uses plugins in a way
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
4
fb6f1de06be0 Start with a simplistic event handling system, which uses plugins in a way
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
5 This code abstracts event handling in MoinMoin,
fb6f1de06be0 Start with a simplistic event handling system, which uses plugins in a way
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
6 currently for notifications. It implements the observer pattern.
fb6f1de06be0 Start with a simplistic event handling system, which uses plugins in a way
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
7
2064
5cc8f6714297 Add more event types. Return a list of messages generated by event handlers to caller.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2061
diff changeset
8 @copyright: 2007 by Karol Nowak <grywacz@gmail.com>
5cc8f6714297 Add more event types. Return a list of messages generated by event handlers to caller.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2061
diff changeset
9 @license: GNU GPL, see COPYING for details.
2058
fb6f1de06be0 Start with a simplistic event handling system, which uses plugins in a way
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
10 """
fb6f1de06be0 Start with a simplistic event handling system, which uses plugins in a way
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
11
2323
a43db0817020 Use stdlib's logging instead of prints.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2318
diff changeset
12 import logging
a43db0817020 Use stdlib's logging instead of prints.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2318
diff changeset
13
2058
fb6f1de06be0 Start with a simplistic event handling system, which uses plugins in a way
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
14 from MoinMoin import wikiutil
fb6f1de06be0 Start with a simplistic event handling system, which uses plugins in a way
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
15 from MoinMoin.util import pysupport
2073
afa784d8d58d Handle PluginErrors while loading event handlers gracefully.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2064
diff changeset
16 from MoinMoin.wikiutil import PluginAttributeError
2058
fb6f1de06be0 Start with a simplistic event handling system, which uses plugins in a way
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
17
fb6f1de06be0 Start with a simplistic event handling system, which uses plugins in a way
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
18 # Create a list of extension actions from the package directory
fb6f1de06be0 Start with a simplistic event handling system, which uses plugins in a way
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
19 modules = pysupport.getPackageModules(__file__)
fb6f1de06be0 Start with a simplistic event handling system, which uses plugins in a way
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
20
2323
a43db0817020 Use stdlib's logging instead of prints.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2318
diff changeset
21 # A module-wide Logger, don't use it from outside
a43db0817020 Use stdlib's logging instead of prints.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2318
diff changeset
22 logger = logging.getLogger("events")
a43db0817020 Use stdlib's logging instead of prints.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2318
diff changeset
23 logger.setLevel(logging.DEBUG)
a43db0817020 Use stdlib's logging instead of prints.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2318
diff changeset
24 logger.addHandler(logging.StreamHandler())
a43db0817020 Use stdlib's logging instead of prints.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2318
diff changeset
25
2464
3c5b329afe4b Add a pseudo-getText function to that strings can get into .po files
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2461
diff changeset
26 # Dummy pseudo-getText function used in event descriptions,
3c5b329afe4b Add a pseudo-getText function to that strings can get into .po files
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2461
diff changeset
27 # so that they get into .po files
3c5b329afe4b Add a pseudo-getText function to that strings can get into .po files
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2461
diff changeset
28 _ = lambda x: x
2086
c8bc6df45964 Formatting fixes according to PEP 8.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2077
diff changeset
29
2492
5b8e8e7db56f Whitespace fixes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2469
diff changeset
30
2152
cf4c4a3d6085 Add a list of selectable events user wants to be notified about.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2145
diff changeset
31 class Event(object):
2058
fb6f1de06be0 Start with a simplistic event handling system, which uses plugins in a way
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
32 """A class handling information common to all events."""
2633
f42fb1ae0a38 Fixes to the Event.name commit.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2628
diff changeset
33
f42fb1ae0a38 Fixes to the Event.name commit.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2628
diff changeset
34 # NOTE: each Event subclass must have a unique name attribute
f42fb1ae0a38 Fixes to the Event.name commit.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2628
diff changeset
35 name = u"Event"
f42fb1ae0a38 Fixes to the Event.name commit.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2628
diff changeset
36
2064
5cc8f6714297 Add more event types. Return a list of messages generated by event handlers to caller.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2061
diff changeset
37 def __init__(self, request):
5cc8f6714297 Add more event types. Return a list of messages generated by event handlers to caller.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2061
diff changeset
38 self.request = request
2086
c8bc6df45964 Formatting fixes according to PEP 8.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2077
diff changeset
39
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2152
diff changeset
40
2091
7af58454aafa Send an event when user changes her jabber id, force jid to be unique.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2086
diff changeset
41 class PageEvent(Event):
2061
7547652ffb6f Change Event -> Observable, add a helper PageEvent class.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2058
diff changeset
42 """An event related to a page change"""
2633
f42fb1ae0a38 Fixes to the Event.name commit.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2628
diff changeset
43
f42fb1ae0a38 Fixes to the Event.name commit.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2628
diff changeset
44 name = u"PageEvent"
f42fb1ae0a38 Fixes to the Event.name commit.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2628
diff changeset
45
2094
9ee68c8b409b Style fixes as suggested by Thomas.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2091
diff changeset
46 def __init__(self, request):
9ee68c8b409b Style fixes as suggested by Thomas.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2091
diff changeset
47 Event.__init__(self, request)
2086
c8bc6df45964 Formatting fixes according to PEP 8.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2077
diff changeset
48
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2152
diff changeset
49
2061
7547652ffb6f Change Event -> Observable, add a helper PageEvent class.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2058
diff changeset
50 class PageChangedEvent(PageEvent):
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2152
diff changeset
51
2628
35690680ecac Use event's "name" attribute instead of class name.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2492
diff changeset
52 name = u"PageChangedEvent"
2469
663867be4afc Add a separate TrivialPageChangedEvent users can subscribe to.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2467
diff changeset
53 description = _(u"""Page has been modified""")
2152
cf4c4a3d6085 Add a list of selectable events user wants to be notified about.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2145
diff changeset
54 req_superuser = False
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
55
2469
663867be4afc Add a separate TrivialPageChangedEvent users can subscribe to.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2467
diff changeset
56 def __init__(self, request, page, comment):
2094
9ee68c8b409b Style fixes as suggested by Thomas.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2091
diff changeset
57 PageEvent.__init__(self, request)
2064
5cc8f6714297 Add more event types. Return a list of messages generated by event handlers to caller.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2061
diff changeset
58 self.page = page
5cc8f6714297 Add more event types. Return a list of messages generated by event handlers to caller.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2061
diff changeset
59 self.comment = comment
2469
663867be4afc Add a separate TrivialPageChangedEvent users can subscribe to.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2467
diff changeset
60
663867be4afc Add a separate TrivialPageChangedEvent users can subscribe to.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2467
diff changeset
61
663867be4afc Add a separate TrivialPageChangedEvent users can subscribe to.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2467
diff changeset
62 class TrivialPageChangedEvent(PageEvent):
663867be4afc Add a separate TrivialPageChangedEvent users can subscribe to.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2467
diff changeset
63
2628
35690680ecac Use event's "name" attribute instead of class name.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2492
diff changeset
64 name = u"TrivialPageChangedEvent"
2469
663867be4afc Add a separate TrivialPageChangedEvent users can subscribe to.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2467
diff changeset
65 description = _(u"Page has been modified in a trivial fashion")
663867be4afc Add a separate TrivialPageChangedEvent users can subscribe to.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2467
diff changeset
66 req_superuser = False
663867be4afc Add a separate TrivialPageChangedEvent users can subscribe to.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2467
diff changeset
67
663867be4afc Add a separate TrivialPageChangedEvent users can subscribe to.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2467
diff changeset
68 def __init__(self, request, page, comment):
663867be4afc Add a separate TrivialPageChangedEvent users can subscribe to.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2467
diff changeset
69 PageEvent.__init__(self, request)
663867be4afc Add a separate TrivialPageChangedEvent users can subscribe to.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2467
diff changeset
70 self.page = page
663867be4afc Add a separate TrivialPageChangedEvent users can subscribe to.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2467
diff changeset
71 self.comment = comment
2086
c8bc6df45964 Formatting fixes according to PEP 8.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2077
diff changeset
72
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
73
2061
7547652ffb6f Change Event -> Observable, add a helper PageEvent class.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2058
diff changeset
74 class PageRenamedEvent(PageEvent):
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
75
2628
35690680ecac Use event's "name" attribute instead of class name.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2492
diff changeset
76 name = u"PageRenamedEvent"
2464
3c5b329afe4b Add a pseudo-getText function to that strings can get into .po files
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2461
diff changeset
77 description = _(u"""Page has been renamed""")
2329
9a71ea0c941b Add support for PageRenamed event. Not tested yet.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2323
diff changeset
78 req_superuser = False
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
79
2461
f456dc2048d1 i18n should now work. First step, no caching yet.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2399
diff changeset
80 def __init__(self, request, page, old_page, comment=""):
2329
9a71ea0c941b Add support for PageRenamed event. Not tested yet.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2323
diff changeset
81 PageEvent.__init__(self, request)
9a71ea0c941b Add support for PageRenamed event. Not tested yet.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2323
diff changeset
82 self.page = page
9a71ea0c941b Add support for PageRenamed event. Not tested yet.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2323
diff changeset
83 self.old_page = old_page
9a71ea0c941b Add support for PageRenamed event. Not tested yet.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2323
diff changeset
84 self.comment = comment
2109
b39379ab47d3 Send notifications when page is deleted + some small fixes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2107
diff changeset
85
b39379ab47d3 Send notifications when page is deleted + some small fixes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2107
diff changeset
86
2061
7547652ffb6f Change Event -> Observable, add a helper PageEvent class.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2058
diff changeset
87 class PageDeletedEvent(PageEvent):
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
88
2628
35690680ecac Use event's "name" attribute instead of class name.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2492
diff changeset
89 name = u"PageDeletedEvent"
2464
3c5b329afe4b Add a pseudo-getText function to that strings can get into .po files
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2461
diff changeset
90 description = _(u"""Page has been deleted""")
2152
cf4c4a3d6085 Add a list of selectable events user wants to be notified about.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2145
diff changeset
91 req_superuser = False
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
92
2109
b39379ab47d3 Send notifications when page is deleted + some small fixes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2107
diff changeset
93 def __init__(self, request, page, comment):
b39379ab47d3 Send notifications when page is deleted + some small fixes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2107
diff changeset
94 PageEvent.__init__(self, request)
b39379ab47d3 Send notifications when page is deleted + some small fixes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2107
diff changeset
95 self.page = page
b39379ab47d3 Send notifications when page is deleted + some small fixes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2107
diff changeset
96 self.comment = comment
2106
1577663f6354 Notify when a new attachment is added to a page. s/JabberBot/jabberbot/.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2095
diff changeset
97
1577663f6354 Notify when a new attachment is added to a page. s/JabberBot/jabberbot/.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2095
diff changeset
98
2385
53fbdf5899ff Use the event handling framework to (re)generate xapian indexes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2356
diff changeset
99 class PageCopiedEvent(PageEvent):
53fbdf5899ff Use the event handling framework to (re)generate xapian indexes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2356
diff changeset
100
2628
35690680ecac Use event's "name" attribute instead of class name.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2492
diff changeset
101 name = u"PageCopiedEvent"
2464
3c5b329afe4b Add a pseudo-getText function to that strings can get into .po files
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2461
diff changeset
102 description = _(u"""Page has been copied""")
2385
53fbdf5899ff Use the event handling framework to (re)generate xapian indexes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2356
diff changeset
103 req_superuser = False
53fbdf5899ff Use the event handling framework to (re)generate xapian indexes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2356
diff changeset
104
53fbdf5899ff Use the event handling framework to (re)generate xapian indexes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2356
diff changeset
105 def __init__(self, request, page, old_page, comment):
53fbdf5899ff Use the event handling framework to (re)generate xapian indexes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2356
diff changeset
106 PageEvent.__init__(self, request)
53fbdf5899ff Use the event handling framework to (re)generate xapian indexes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2356
diff changeset
107 self.page = page
53fbdf5899ff Use the event handling framework to (re)generate xapian indexes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2356
diff changeset
108 self.old_page = old_page
53fbdf5899ff Use the event handling framework to (re)generate xapian indexes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2356
diff changeset
109 self.comment = comment
53fbdf5899ff Use the event handling framework to (re)generate xapian indexes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2356
diff changeset
110
53fbdf5899ff Use the event handling framework to (re)generate xapian indexes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2356
diff changeset
111
2064
5cc8f6714297 Add more event types. Return a list of messages generated by event handlers to caller.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2061
diff changeset
112 class FileAttachedEvent(PageEvent):
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
113
2628
35690680ecac Use event's "name" attribute instead of class name.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2492
diff changeset
114 name = u"FileAttachedEvent"
2464
3c5b329afe4b Add a pseudo-getText function to that strings can get into .po files
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2461
diff changeset
115 description = _(u"""A new attachment has been added""")
2152
cf4c4a3d6085 Add a list of selectable events user wants to be notified about.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2145
diff changeset
116 req_superuser = False
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
117
2356
1d60f9aa07d1 Email notification about new attachments. Some i18n issues left to be fixed.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2337
diff changeset
118 def __init__(self, request, pagename, name, size):
2107
645bbc7fe2b5 Add forgotten invocation of parent constructor.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2106
diff changeset
119 PageEvent.__init__(self, request)
2106
1577663f6354 Notify when a new attachment is added to a page. s/JabberBot/jabberbot/.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2095
diff changeset
120 self.request = request
1577663f6354 Notify when a new attachment is added to a page. s/JabberBot/jabberbot/.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2095
diff changeset
121 self.pagename = pagename
2356
1d60f9aa07d1 Email notification about new attachments. Some i18n issues left to be fixed.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2337
diff changeset
122 self.name = name
2106
1577663f6354 Notify when a new attachment is added to a page. s/JabberBot/jabberbot/.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2095
diff changeset
123 self.size = size
2064
5cc8f6714297 Add more event types. Return a list of messages generated by event handlers to caller.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2061
diff changeset
124
2086
c8bc6df45964 Formatting fixes according to PEP 8.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2077
diff changeset
125
2064
5cc8f6714297 Add more event types. Return a list of messages generated by event handlers to caller.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2061
diff changeset
126 class PageRevertedEvent(PageEvent):
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
127
2628
35690680ecac Use event's "name" attribute instead of class name.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2492
diff changeset
128 name = u"PageRevertedEvent"
2464
3c5b329afe4b Add a pseudo-getText function to that strings can get into .po files
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2461
diff changeset
129 description = _(u"""A page has been reverted to a previous state""")
2152
cf4c4a3d6085 Add a list of selectable events user wants to be notified about.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2145
diff changeset
130 req_superuser = False
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
131
2064
5cc8f6714297 Add more event types. Return a list of messages generated by event handlers to caller.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2061
diff changeset
132 def __init__(self, request, pagename, previous, current):
2094
9ee68c8b409b Style fixes as suggested by Thomas.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2091
diff changeset
133 PageEvent.__init__(self, request)
2064
5cc8f6714297 Add more event types. Return a list of messages generated by event handlers to caller.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2061
diff changeset
134 self.pagename = pagename
5cc8f6714297 Add more event types. Return a list of messages generated by event handlers to caller.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2061
diff changeset
135 self.previous = previous
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
136 self.current = current
2064
5cc8f6714297 Add more event types. Return a list of messages generated by event handlers to caller.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2061
diff changeset
137
2086
c8bc6df45964 Formatting fixes according to PEP 8.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2077
diff changeset
138
2064
5cc8f6714297 Add more event types. Return a list of messages generated by event handlers to caller.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2061
diff changeset
139 class SubscribedToPageEvent(PageEvent):
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
140
2628
35690680ecac Use event's "name" attribute instead of class name.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2492
diff changeset
141 name = u"SubscribedToPageEvent"
2467
31b3d03bd1ea s/An/A/
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2464
diff changeset
142 description = _(u"""A user has subscribed to a page""")
2152
cf4c4a3d6085 Add a list of selectable events user wants to be notified about.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2145
diff changeset
143 req_superuser = True
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
144
2064
5cc8f6714297 Add more event types. Return a list of messages generated by event handlers to caller.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2061
diff changeset
145 def __init__(self, request, pagename, username):
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
146 PageEvent.__init__(self, request)
2064
5cc8f6714297 Add more event types. Return a list of messages generated by event handlers to caller.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2061
diff changeset
147 self.pagename = pagename
5cc8f6714297 Add more event types. Return a list of messages generated by event handlers to caller.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2061
diff changeset
148 self.username = username
5cc8f6714297 Add more event types. Return a list of messages generated by event handlers to caller.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2061
diff changeset
149
2086
c8bc6df45964 Formatting fixes according to PEP 8.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2077
diff changeset
150
2091
7af58454aafa Send an event when user changes her jabber id, force jid to be unique.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2086
diff changeset
151 class JabberIDSetEvent(Event):
7af58454aafa Send an event when user changes her jabber id, force jid to be unique.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2086
diff changeset
152 """ Sent when user changes her Jabber ID """
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
153
2091
7af58454aafa Send an event when user changes her jabber id, force jid to be unique.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2086
diff changeset
154 def __init__(self, request, jid):
7af58454aafa Send an event when user changes her jabber id, force jid to be unique.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2086
diff changeset
155 Event.__init__(self, request)
7af58454aafa Send an event when user changes her jabber id, force jid to be unique.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2086
diff changeset
156 self.jid = jid
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
157
2095
258d6e648eca Add a JabberIDUnsetEvent; make some private symbols internal in MoinMoin.events
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2094
diff changeset
158 class JabberIDUnsetEvent(Event):
258d6e648eca Add a JabberIDUnsetEvent; make some private symbols internal in MoinMoin.events
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2094
diff changeset
159 """ Sent when Jabber ID is no longer used
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
160
2095
258d6e648eca Add a JabberIDUnsetEvent; make some private symbols internal in MoinMoin.events
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2094
diff changeset
161 Obviously this will be usually sent along with JabberIDSetEvent,
258d6e648eca Add a JabberIDUnsetEvent; make some private symbols internal in MoinMoin.events
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2094
diff changeset
162 because we require user's jabber id to be unique by default.
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
163
2095
258d6e648eca Add a JabberIDUnsetEvent; make some private symbols internal in MoinMoin.events
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2094
diff changeset
164 """
258d6e648eca Add a JabberIDUnsetEvent; make some private symbols internal in MoinMoin.events
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2094
diff changeset
165 def __init__(self, request, jid):
258d6e648eca Add a JabberIDUnsetEvent; make some private symbols internal in MoinMoin.events
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2094
diff changeset
166 Event.__init__(self, request)
258d6e648eca Add a JabberIDUnsetEvent; make some private symbols internal in MoinMoin.events
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2094
diff changeset
167 self.jid = jid
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
168
2145
f153b3155240 Send notifications about creation of users to Superusers with JID set.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2109
diff changeset
169 class UserCreatedEvent(Event):
f153b3155240 Send notifications about creation of users to Superusers with JID set.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2109
diff changeset
170 """ Sent when a new user has been created """
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
171
2628
35690680ecac Use event's "name" attribute instead of class name.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2492
diff changeset
172 name = u"UserCreatedEvent"
2464
3c5b329afe4b Add a pseudo-getText function to that strings can get into .po files
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2461
diff changeset
173 description = _(u"""A new account has been created""")
2152
cf4c4a3d6085 Add a list of selectable events user wants to be notified about.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2145
diff changeset
174 req_superuser = True
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
175
2145
f153b3155240 Send notifications about creation of users to Superusers with JID set.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2109
diff changeset
176 def __init__(self, request, user):
f153b3155240 Send notifications about creation of users to Superusers with JID set.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2109
diff changeset
177 Event.__init__(self, request)
f153b3155240 Send notifications about creation of users to Superusers with JID set.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2109
diff changeset
178 self.user = user
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
179
2396
cf85b6916d17 Add a PagePreSave event; abort page save if handlers return Abort.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2385
diff changeset
180 class PagePreSaveEvent(Event):
cf85b6916d17 Add a PagePreSave event; abort page save if handlers return Abort.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2385
diff changeset
181 """ Event sent when a page is about to be saved
cf85b6916d17 Add a PagePreSave event; abort page save if handlers return Abort.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2385
diff changeset
182
cf85b6916d17 Add a PagePreSave event; abort page save if handlers return Abort.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2385
diff changeset
183 This can be used to abort a save, for instance,
cf85b6916d17 Add a PagePreSave event; abort page save if handlers return Abort.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2385
diff changeset
184 if handler returns
cf85b6916d17 Add a PagePreSave event; abort page save if handlers return Abort.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2385
diff changeset
185
cf85b6916d17 Add a PagePreSave event; abort page save if handlers return Abort.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2385
diff changeset
186 """
2633
f42fb1ae0a38 Fixes to the Event.name commit.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2628
diff changeset
187
f42fb1ae0a38 Fixes to the Event.name commit.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2628
diff changeset
188 name = u"PagePreSaveEvent"
f42fb1ae0a38 Fixes to the Event.name commit.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2628
diff changeset
189
2396
cf85b6916d17 Add a PagePreSave event; abort page save if handlers return Abort.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2385
diff changeset
190 def __init__(self, request, page_editor, new_text):
cf85b6916d17 Add a PagePreSave event; abort page save if handlers return Abort.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2385
diff changeset
191 Event.__init__(self, request)
cf85b6916d17 Add a PagePreSave event; abort page save if handlers return Abort.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2385
diff changeset
192 self.page_editor = page_editor
cf85b6916d17 Add a PagePreSave event; abort page save if handlers return Abort.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2385
diff changeset
193 self.new_text = new_text
cf85b6916d17 Add a PagePreSave event; abort page save if handlers return Abort.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2385
diff changeset
194
cf85b6916d17 Add a PagePreSave event; abort page save if handlers return Abort.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2385
diff changeset
195
2318
062b76cf8d48 Introduce an base EventResult class for event handler return values.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2312
diff changeset
196 class EventResult:
062b76cf8d48 Introduce an base EventResult class for event handler return values.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2312
diff changeset
197 """ This is a base class for messages passed from event handlers """
062b76cf8d48 Introduce an base EventResult class for event handler return values.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2312
diff changeset
198 pass
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
199
2396
cf85b6916d17 Add a PagePreSave event; abort page save if handlers return Abort.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2385
diff changeset
200 class Abort(EventResult):
cf85b6916d17 Add a PagePreSave event; abort page save if handlers return Abort.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2385
diff changeset
201 """ Result returned if handler wants to abort operation that sent the event """
cf85b6916d17 Add a PagePreSave event; abort page save if handlers return Abort.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2385
diff changeset
202 def __init__(self, reason):
cf85b6916d17 Add a PagePreSave event; abort page save if handlers return Abort.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2385
diff changeset
203 """
cf85b6916d17 Add a PagePreSave event; abort page save if handlers return Abort.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2385
diff changeset
204 @param reason: human-readable reason of failure
cf85b6916d17 Add a PagePreSave event; abort page save if handlers return Abort.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2385
diff changeset
205 """
cf85b6916d17 Add a PagePreSave event; abort page save if handlers return Abort.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2385
diff changeset
206 self.reason = reason
2399
245181ec9fe2 Whitespace fixes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2396
diff changeset
207
2396
cf85b6916d17 Add a PagePreSave event; abort page save if handlers return Abort.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2385
diff changeset
208
2307
fe37834deb3d Move a list of event handlers and subscribable events to config.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2152
diff changeset
209 def get_handlers(cfg):
2058
fb6f1de06be0 Start with a simplistic event handling system, which uses plugins in a way
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
210 """Create a list of available event handlers.
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
211
2058
fb6f1de06be0 Start with a simplistic event handling system, which uses plugins in a way
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
212 Each handler is a handle() function defined in an plugin,
fb6f1de06be0 Start with a simplistic event handling system, which uses plugins in a way
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
213 pretty much like in case of actions.
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
214
2307
fe37834deb3d Move a list of event handlers and subscribable events to config.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2152
diff changeset
215 TODO: maybe make it less dumb? ;-)
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
216
2307
fe37834deb3d Move a list of event handlers and subscribable events to config.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2152
diff changeset
217 """
fe37834deb3d Move a list of event handlers and subscribable events to config.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2152
diff changeset
218 event_handlers = []
2058
fb6f1de06be0 Start with a simplistic event handling system, which uses plugins in a way
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
219 names = wikiutil.getPlugins("events", cfg)
fb6f1de06be0 Start with a simplistic event handling system, which uses plugins in a way
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
220
fb6f1de06be0 Start with a simplistic event handling system, which uses plugins in a way
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
221 for name in names:
2073
afa784d8d58d Handle PluginErrors while loading event handlers gracefully.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2064
diff changeset
222 try:
afa784d8d58d Handle PluginErrors while loading event handlers gracefully.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2064
diff changeset
223 handler = wikiutil.importPlugin(cfg, "events", name, "handle")
afa784d8d58d Handle PluginErrors while loading event handlers gracefully.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2064
diff changeset
224 except PluginAttributeError:
afa784d8d58d Handle PluginErrors while loading event handlers gracefully.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2064
diff changeset
225 handler = None
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
226
2058
fb6f1de06be0 Start with a simplistic event handling system, which uses plugins in a way
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
227 if handler is not None:
2307
fe37834deb3d Move a list of event handlers and subscribable events to config.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2152
diff changeset
228 event_handlers.append(handler)
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
229
2307
fe37834deb3d Move a list of event handlers and subscribable events to config.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2152
diff changeset
230 return event_handlers
2058
fb6f1de06be0 Start with a simplistic event handling system, which uses plugins in a way
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
231
2086
c8bc6df45964 Formatting fixes according to PEP 8.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2077
diff changeset
232
2058
fb6f1de06be0 Start with a simplistic event handling system, which uses plugins in a way
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
233 def send_event(event):
2312
a85d51778eda Remove a forgotten line, improve comment.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2307
diff changeset
234 """Function called from outside to process an event
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
235
2312
a85d51778eda Remove a forgotten line, improve comment.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2307
diff changeset
236 @return: a list of messages returned by handlers
a85d51778eda Remove a forgotten line, improve comment.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2307
diff changeset
237 @rtype: list
a85d51778eda Remove a forgotten line, improve comment.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2307
diff changeset
238 """
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
239
2064
5cc8f6714297 Add more event types. Return a list of messages generated by event handlers to caller.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2061
diff changeset
240 # A list of messages generated by event handlers, passed back to caller
5cc8f6714297 Add more event types. Return a list of messages generated by event handlers to caller.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2061
diff changeset
241 msg = []
2307
fe37834deb3d Move a list of event handlers and subscribable events to config.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2152
diff changeset
242 cfg = event.request.cfg
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
243
2058
fb6f1de06be0 Start with a simplistic event handling system, which uses plugins in a way
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
244 # Try to handle the event with each available handler (for now)
2307
fe37834deb3d Move a list of event handlers and subscribable events to config.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2152
diff changeset
245 for handle in cfg.event_handlers:
2064
5cc8f6714297 Add more event types. Return a list of messages generated by event handlers to caller.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2061
diff changeset
246 retval = handle(event)
2385
53fbdf5899ff Use the event handling framework to (re)generate xapian indexes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2356
diff changeset
247
53fbdf5899ff Use the event handling framework to (re)generate xapian indexes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2356
diff changeset
248 assert retval is None or isinstance(retval, EventResult)
53fbdf5899ff Use the event handling framework to (re)generate xapian indexes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2356
diff changeset
249
2318
062b76cf8d48 Introduce an base EventResult class for event handler return values.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2312
diff changeset
250 if retval:
2064
5cc8f6714297 Add more event types. Return a list of messages generated by event handlers to caller.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2061
diff changeset
251 msg.append(retval)
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
252
2076
0128bbaf0172 Add newlines at the end of files, fix some overzealous deletion.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2073
diff changeset
253 return msg
2152
cf4c4a3d6085 Add a list of selectable events user wants to be notified about.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2145
diff changeset
254
cf4c4a3d6085 Add a list of selectable events user wants to be notified about.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2145
diff changeset
255 def get_subscribable_events():
cf4c4a3d6085 Add a list of selectable events user wants to be notified about.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2145
diff changeset
256 """Create and return a list of user-visible events
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
257
2152
cf4c4a3d6085 Add a list of selectable events user wants to be notified about.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2145
diff changeset
258 @return: A list of user-visible events described by dictionaries
cf4c4a3d6085 Add a list of selectable events user wants to be notified about.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2145
diff changeset
259 @rtype: dict
cf4c4a3d6085 Add a list of selectable events user wants to be notified about.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2145
diff changeset
260 """
cf4c4a3d6085 Add a list of selectable events user wants to be notified about.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2145
diff changeset
261 defs = globals()
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
262 subscribable_events = {}
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
263
2307
fe37834deb3d Move a list of event handlers and subscribable events to config.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2152
diff changeset
264 for ev in defs.values():
2628
35690680ecac Use event's "name" attribute instead of class name.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2492
diff changeset
265 if type(ev) is type and issubclass(ev, Event) and ev.__dict__.has_key("description") and ev.__dict__.has_key("name"):
35690680ecac Use event's "name" attribute instead of class name.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2492
diff changeset
266 subscribable_events[ev.name] = {'desc': ev.description, 'superuser': ev.req_superuser}
35690680ecac Use event's "name" attribute instead of class name.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2492
diff changeset
267
2307
fe37834deb3d Move a list of event handlers and subscribable events to config.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2152
diff changeset
268 return subscribable_events
2464
3c5b329afe4b Add a pseudo-getText function to that strings can get into .po files
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2461
diff changeset
269
3c5b329afe4b Add a pseudo-getText function to that strings can get into .po files
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2461
diff changeset
270 # Get rid of the dummy getText so that it doesn't get imported with *
3c5b329afe4b Add a pseudo-getText function to that strings can get into .po files
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2461
diff changeset
271 del _