annotate MoinMoin/events/__init__.py @ 6076:f4ec84967c27

add colon to make log_attempt even more parseable
author 'Karl O. Pinc' <kop@meme.com>
date Mon, 15 Sep 2014 22:10:45 -0500
parents 3f7f4cef7c2a
children dca00e9c5bcd
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
3110
a48929a5036c logging: make it work correctly by doing logging configuration very early
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3107
diff changeset
12 from MoinMoin import log
3637
92d08c1975b0 jabber notifications: don't translate log messages, fix non-existing logger
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3110
diff changeset
13 logging = log.getLogger(__name__)
2323
a43db0817020 Use stdlib's logging instead of prints.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2318
diff changeset
14
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
15 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
16 from MoinMoin.util import pysupport
6061
50251583a7bb log user account creation with the abuse logger
'Karl O. Pinc' <kop@meme.com>
parents: 5280
diff changeset
17 from MoinMoin.util.abuse import log_attempt
2073
afa784d8d58d Handle PluginErrors while loading event handlers gracefully.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2064
diff changeset
18 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
19
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 # 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
21 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
22
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
23 # 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
24 # 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
25 _ = lambda x: x
2086
c8bc6df45964 Formatting fixes according to PEP 8.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2077
diff changeset
26
2492
5b8e8e7db56f Whitespace fixes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2469
diff changeset
27
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
28 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
29 """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
30
f42fb1ae0a38 Fixes to the Event.name commit.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2628
diff changeset
31 # 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
32 name = u"Event"
f42fb1ae0a38 Fixes to the Event.name commit.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2628
diff changeset
33
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
34 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
35 self.request = request
2086
c8bc6df45964 Formatting fixes according to PEP 8.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2077
diff changeset
36
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2152
diff changeset
37
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
38 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
39 """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
40
f42fb1ae0a38 Fixes to the Event.name commit.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2628
diff changeset
41 name = u"PageEvent"
f42fb1ae0a38 Fixes to the Event.name commit.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2628
diff changeset
42
2094
9ee68c8b409b Style fixes as suggested by Thomas.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2091
diff changeset
43 def __init__(self, request):
9ee68c8b409b Style fixes as suggested by Thomas.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2091
diff changeset
44 Event.__init__(self, request)
2086
c8bc6df45964 Formatting fixes according to PEP 8.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2077
diff changeset
45
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2152
diff changeset
46
2061
7547652ffb6f Change Event -> Observable, add a helper PageEvent class.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2058
diff changeset
47 class PageChangedEvent(PageEvent):
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2152
diff changeset
48
2628
35690680ecac Use event's "name" attribute instead of class name.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2492
diff changeset
49 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
50 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
51 req_superuser = False
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
52
2469
663867be4afc Add a separate TrivialPageChangedEvent users can subscribe to.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2467
diff changeset
53 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
54 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
55 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
56 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
57
663867be4afc Add a separate TrivialPageChangedEvent users can subscribe to.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2467
diff changeset
58
663867be4afc Add a separate TrivialPageChangedEvent users can subscribe to.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2467
diff changeset
59 class TrivialPageChangedEvent(PageEvent):
663867be4afc Add a separate TrivialPageChangedEvent users can subscribe to.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2467
diff changeset
60
2628
35690680ecac Use event's "name" attribute instead of class name.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2492
diff changeset
61 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
62 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
63 req_superuser = False
663867be4afc Add a separate TrivialPageChangedEvent users can subscribe to.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2467
diff changeset
64
663867be4afc Add a separate TrivialPageChangedEvent users can subscribe to.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2467
diff changeset
65 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
66 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
67 self.page = page
663867be4afc Add a separate TrivialPageChangedEvent users can subscribe to.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2467
diff changeset
68 self.comment = comment
2086
c8bc6df45964 Formatting fixes according to PEP 8.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2077
diff changeset
69
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
70
2061
7547652ffb6f Change Event -> Observable, add a helper PageEvent class.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2058
diff changeset
71 class PageRenamedEvent(PageEvent):
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
72
2628
35690680ecac Use event's "name" attribute instead of class name.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2492
diff changeset
73 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
74 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
75 req_superuser = False
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
76
2461
f456dc2048d1 i18n should now work. First step, no caching yet.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2399
diff changeset
77 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
78 PageEvent.__init__(self, request)
9a71ea0c941b Add support for PageRenamed event. Not tested yet.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2323
diff changeset
79 self.page = page
9a71ea0c941b Add support for PageRenamed event. Not tested yet.
Karol Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2323
diff changeset
80 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
81 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
82
b39379ab47d3 Send notifications when page is deleted + some small fixes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2107
diff changeset
83
2061
7547652ffb6f Change Event -> Observable, add a helper PageEvent class.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2058
diff changeset
84 class PageDeletedEvent(PageEvent):
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
85
2628
35690680ecac Use event's "name" attribute instead of class name.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2492
diff changeset
86 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
87 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
88 req_superuser = False
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
89
2109
b39379ab47d3 Send notifications when page is deleted + some small fixes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2107
diff changeset
90 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
91 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
92 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
93 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
94
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
95
2385
53fbdf5899ff Use the event handling framework to (re)generate xapian indexes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2356
diff changeset
96 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
97
2628
35690680ecac Use event's "name" attribute instead of class name.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2492
diff changeset
98 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
99 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
100 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
101
53fbdf5899ff Use the event handling framework to (re)generate xapian indexes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2356
diff changeset
102 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
103 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
104 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
105 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
106 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
107
53fbdf5899ff Use the event handling framework to (re)generate xapian indexes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2356
diff changeset
108
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
109 class FileAttachedEvent(PageEvent):
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
110
2628
35690680ecac Use event's "name" attribute instead of class name.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2492
diff changeset
111 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
112 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
113 req_superuser = False
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
114
2638
6e84127a1860 Finally all known bugs fixed, OOB is used to send links with jabber. More...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2633
diff changeset
115 def __init__(self, request, pagename, filename, size):
2107
645bbc7fe2b5 Add forgotten invocation of parent constructor.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2106
diff changeset
116 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
117 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
118 self.pagename = pagename
2638
6e84127a1860 Finally all known bugs fixed, OOB is used to send links with jabber. More...
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2633
diff changeset
119 self.filename = filename
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.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
121
2086
c8bc6df45964 Formatting fixes according to PEP 8.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2077
diff changeset
122
5279
2aa43685e17b AttachFile: added remove_attachment(), made nuke_page use it (details below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3637
diff changeset
123 class FileRemovedEvent(PageEvent):
2aa43685e17b AttachFile: added remove_attachment(), made nuke_page use it (details below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3637
diff changeset
124
2aa43685e17b AttachFile: added remove_attachment(), made nuke_page use it (details below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3637
diff changeset
125 name = u"FileRemovedEvent"
2aa43685e17b AttachFile: added remove_attachment(), made nuke_page use it (details below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3637
diff changeset
126 description = _(u"""An attachment has been removed""")
2aa43685e17b AttachFile: added remove_attachment(), made nuke_page use it (details below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3637
diff changeset
127 req_superuser = False
2aa43685e17b AttachFile: added remove_attachment(), made nuke_page use it (details below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3637
diff changeset
128
2aa43685e17b AttachFile: added remove_attachment(), made nuke_page use it (details below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3637
diff changeset
129 def __init__(self, request, pagename, filename, size):
2aa43685e17b AttachFile: added remove_attachment(), made nuke_page use it (details below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3637
diff changeset
130 PageEvent.__init__(self, request)
2aa43685e17b AttachFile: added remove_attachment(), made nuke_page use it (details below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3637
diff changeset
131 self.request = request
2aa43685e17b AttachFile: added remove_attachment(), made nuke_page use it (details below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3637
diff changeset
132 self.pagename = pagename
2aa43685e17b AttachFile: added remove_attachment(), made nuke_page use it (details below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3637
diff changeset
133 self.filename = filename
2aa43685e17b AttachFile: added remove_attachment(), made nuke_page use it (details below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3637
diff changeset
134 self.size = size
2aa43685e17b AttachFile: added remove_attachment(), made nuke_page use it (details below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3637
diff changeset
135
2aa43685e17b AttachFile: added remove_attachment(), made nuke_page use it (details below)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3637
diff changeset
136
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 class PageRevertedEvent(PageEvent):
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
138
2628
35690680ecac Use event's "name" attribute instead of class name.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2492
diff changeset
139 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
140 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
141 req_superuser = False
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
142
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
143 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
144 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
145 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
146 self.previous = previous
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
147 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
148
2086
c8bc6df45964 Formatting fixes according to PEP 8.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2077
diff changeset
149
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
150 class SubscribedToPageEvent(PageEvent):
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
151
2628
35690680ecac Use event's "name" attribute instead of class name.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2492
diff changeset
152 name = u"SubscribedToPageEvent"
2467
31b3d03bd1ea s/An/A/
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2464
diff changeset
153 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
154 req_superuser = True
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
155
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
156 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
157 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
158 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
159 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
160
2086
c8bc6df45964 Formatting fixes according to PEP 8.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2077
diff changeset
161
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
162 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
163 """ 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
164
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
165 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
166 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
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
5280
d25574af97eb event package: fix PEP8, c&p errors, trivial code changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5279
diff changeset
169
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
170 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
171 """ 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
172
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
173 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
174 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
175
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
176 """
258d6e648eca Add a JabberIDUnsetEvent; make some private symbols internal in MoinMoin.events
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2094
diff changeset
177 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
178 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
179 self.jid = jid
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
180
5280
d25574af97eb event package: fix PEP8, c&p errors, trivial code changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5279
diff changeset
181
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
182 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
183 """ 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
184
2628
35690680ecac Use event's "name" attribute instead of class name.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2492
diff changeset
185 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
186 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
187 req_superuser = True
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
188
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
189 def __init__(self, request, user):
6075
3f7f4cef7c2a make log_attempt output easily parsed
'Karl O. Pinc' <kop@meme.com>
parents: 6061
diff changeset
190 log_attempt('event/newaccount', True, request, user.name)
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
191 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
192 self.user = user
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
193
5280
d25574af97eb event package: fix PEP8, c&p errors, trivial code changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5279
diff changeset
194
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
195 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
196 """ 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
197
5280
d25574af97eb event package: fix PEP8, c&p errors, trivial code changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5279
diff changeset
198 This can be used to abort a save, for instance, if handler returns Abort.
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
199 """
2633
f42fb1ae0a38 Fixes to the Event.name commit.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2628
diff changeset
200
f42fb1ae0a38 Fixes to the Event.name commit.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2628
diff changeset
201 name = u"PagePreSaveEvent"
f42fb1ae0a38 Fixes to the Event.name commit.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2628
diff changeset
202
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
203 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
204 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
205 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
206 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
207
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
2318
062b76cf8d48 Introduce an base EventResult class for event handler return values.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2312
diff changeset
209 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
210 """ 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
211 pass
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
212
5280
d25574af97eb event package: fix PEP8, c&p errors, trivial code changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5279
diff changeset
213
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
214 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
215 """ 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
216 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
217 """
cf85b6916d17 Add a PagePreSave event; abort page save if handlers return Abort.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2385
diff changeset
218 @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
219 """
cf85b6916d17 Add a PagePreSave event; abort page save if handlers return Abort.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2385
diff changeset
220 self.reason = reason
2399
245181ec9fe2 Whitespace fixes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2396
diff changeset
221
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
222
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
223 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
224 """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
225
5280
d25574af97eb event package: fix PEP8, c&p errors, trivial code changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5279
diff changeset
226 Each handler is a handle() function defined in a plugin,
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 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
228
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
229 TODO: maybe make it less dumb? ;-)
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 """
fe37834deb3d Move a list of event handlers and subscribable events to config.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2152
diff changeset
231 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
232 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
233
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
234 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
235 try:
afa784d8d58d Handle PluginErrors while loading event handlers gracefully.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2064
diff changeset
236 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
237 except PluginAttributeError:
afa784d8d58d Handle PluginErrors while loading event handlers gracefully.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2064
diff changeset
238 handler = None
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
239
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
240 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
241 event_handlers.append(handler)
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
242
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
243 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
244
2086
c8bc6df45964 Formatting fixes according to PEP 8.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2077
diff changeset
245
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
246 def send_event(event):
2312
a85d51778eda Remove a forgotten line, improve comment.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2307
diff changeset
247 """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
248
2312
a85d51778eda Remove a forgotten line, improve comment.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2307
diff changeset
249 @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
250 @rtype: list
a85d51778eda Remove a forgotten line, improve comment.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2307
diff changeset
251 """
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
252
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
253 # 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
254 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
255 cfg = event.request.cfg
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
256
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
257 # 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
258 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
259 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
260
53fbdf5899ff Use the event handling framework to (re)generate xapian indexes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2356
diff changeset
261 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
262
2318
062b76cf8d48 Introduce an base EventResult class for event handler return values.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2312
diff changeset
263 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
264 msg.append(retval)
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
265
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
266 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
267
5280
d25574af97eb event package: fix PEP8, c&p errors, trivial code changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5279
diff changeset
268
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
269 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
270 """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
271
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
272 @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
273 @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
274 """
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
275 defs = globals()
2337
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
276 subscribable_events = {}
1d85514968a2 Fix remaining excessive white space characters.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2336
diff changeset
277
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
278 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
279 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
280 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
281
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
282 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
283
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
284 # 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
285 del _
5280
d25574af97eb event package: fix PEP8, c&p errors, trivial code changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5279
diff changeset
286