comparison MoinMoin/events/__init__.py @ 2337:1d85514968a2

Fix remaining excessive white space characters.
author Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
date Wed, 04 Jul 2007 12:12:00 +0200
parents 10be78f1fa97
children 1d60f9aa07d1
comparison
equal deleted inserted replaced
2336:10be78f1fa97 2337:1d85514968a2
38 38
39 class PageChangedEvent(PageEvent): 39 class PageChangedEvent(PageEvent):
40 40
41 description = u"""Page has been modified (edit, creation, deletion)""" 41 description = u"""Page has been modified (edit, creation, deletion)"""
42 req_superuser = False 42 req_superuser = False
43 43
44 def __init__(self, request, page, comment, trivial): 44 def __init__(self, request, page, comment, trivial):
45 PageEvent.__init__(self, request) 45 PageEvent.__init__(self, request)
46 self.page = page 46 self.page = page
47 self.comment = comment 47 self.comment = comment
48 self.trivial = trivial 48 self.trivial = trivial
49 49
50 50
51 class PageRenamedEvent(PageEvent): 51 class PageRenamedEvent(PageEvent):
52 52
53 description = u"""Page has been renamed""" 53 description = u"""Page has been renamed"""
54 req_superuser = False 54 req_superuser = False
55 55
56 def __init__(self, request, page, old_page, comment): 56 def __init__(self, request, page, old_page, comment):
57 PageEvent.__init__(self, request) 57 PageEvent.__init__(self, request)
58 self.page = page 58 self.page = page
59 self.old_page = old_page 59 self.old_page = old_page
60 self.comment = comment 60 self.comment = comment
61 61
62 62
63 class PageDeletedEvent(PageEvent): 63 class PageDeletedEvent(PageEvent):
64 64
65 description = u"""Page has been deleted""" 65 description = u"""Page has been deleted"""
66 req_superuser = False 66 req_superuser = False
67 67
68 def __init__(self, request, page, comment): 68 def __init__(self, request, page, comment):
69 PageEvent.__init__(self, request) 69 PageEvent.__init__(self, request)
70 self.request = request 70 self.request = request
71 self.page = page 71 self.page = page
72 self.comment = comment 72 self.comment = comment
73 73
74 74
75 class FileAttachedEvent(PageEvent): 75 class FileAttachedEvent(PageEvent):
76 76
77 description = u"""A new attachment has been added""" 77 description = u"""A new attachment has been added"""
78 req_superuser = False 78 req_superuser = False
79 79
80 def __init__(self, request, pagename, attachment_name, size): 80 def __init__(self, request, pagename, attachment_name, size):
81 PageEvent.__init__(self, request) 81 PageEvent.__init__(self, request)
82 self.request = request 82 self.request = request
83 self.pagename = pagename 83 self.pagename = pagename
84 self.attachment_name = attachment_name 84 self.attachment_name = attachment_name
85 self.size = size 85 self.size = size
86 86
87 87
88 class PageRevertedEvent(PageEvent): 88 class PageRevertedEvent(PageEvent):
89 89
90 description = u"""A page has been reverted to a previous state""" 90 description = u"""A page has been reverted to a previous state"""
91 req_superuser = False 91 req_superuser = False
92 92
93 def __init__(self, request, pagename, previous, current): 93 def __init__(self, request, pagename, previous, current):
94 PageEvent.__init__(self, request) 94 PageEvent.__init__(self, request)
95 self.pagename = pagename 95 self.pagename = pagename
96 self.previous = previous 96 self.previous = previous
97 self.current = current 97 self.current = current
98 98
99 99
100 class SubscribedToPageEvent(PageEvent): 100 class SubscribedToPageEvent(PageEvent):
101 101
102 description = u"""An user has subscribed to a page""" 102 description = u"""An user has subscribed to a page"""
103 req_superuser = True 103 req_superuser = True
104 104
105 def __init__(self, request, pagename, username): 105 def __init__(self, request, pagename, username):
106 PageEvent.__init__(self, request) 106 PageEvent.__init__(self, request)
107 self.pagename = pagename 107 self.pagename = pagename
108 self.username = username 108 self.username = username
109 109
110 110
111 class JabberIDSetEvent(Event): 111 class JabberIDSetEvent(Event):
112 """ Sent when user changes her Jabber ID """ 112 """ Sent when user changes her Jabber ID """
113 113
114 def __init__(self, request, jid): 114 def __init__(self, request, jid):
115 Event.__init__(self, request) 115 Event.__init__(self, request)
116 self.jid = jid 116 self.jid = jid
117 117
118 class JabberIDUnsetEvent(Event): 118 class JabberIDUnsetEvent(Event):
119 """ Sent when Jabber ID is no longer used 119 """ Sent when Jabber ID is no longer used
120 120
121 Obviously this will be usually sent along with JabberIDSetEvent, 121 Obviously this will be usually sent along with JabberIDSetEvent,
122 because we require user's jabber id to be unique by default. 122 because we require user's jabber id to be unique by default.
123 123
124 """ 124 """
125 def __init__(self, request, jid): 125 def __init__(self, request, jid):
126 Event.__init__(self, request) 126 Event.__init__(self, request)
127 self.jid = jid 127 self.jid = jid
128 128
129 class UserCreatedEvent(Event): 129 class UserCreatedEvent(Event):
130 """ Sent when a new user has been created """ 130 """ Sent when a new user has been created """
131 131
132 description = u"""A new account has been created""" 132 description = u"""A new account has been created"""
133 req_superuser = True 133 req_superuser = True
134 134
135 def __init__(self, request, user): 135 def __init__(self, request, user):
136 Event.__init__(self, request) 136 Event.__init__(self, request)
137 self.user = user 137 self.user = user
138 138
139 class EventResult: 139 class EventResult:
140 """ This is a base class for messages passed from event handlers """ 140 """ This is a base class for messages passed from event handlers """
141 pass 141 pass
142 142
143 def get_handlers(cfg): 143 def get_handlers(cfg):
144 """Create a list of available event handlers. 144 """Create a list of available event handlers.
145 145
146 Each handler is a handle() function defined in an plugin, 146 Each handler is a handle() function defined in an plugin,
147 pretty much like in case of actions. 147 pretty much like in case of actions.
148 148
149 TODO: maybe make it less dumb? ;-) 149 TODO: maybe make it less dumb? ;-)
150 150
151 """ 151 """
152 event_handlers = [] 152 event_handlers = []
153 names = wikiutil.getPlugins("events", cfg) 153 names = wikiutil.getPlugins("events", cfg)
154 154
155 for name in names: 155 for name in names:
156 try: 156 try:
157 handler = wikiutil.importPlugin(cfg, "events", name, "handle") 157 handler = wikiutil.importPlugin(cfg, "events", name, "handle")
158 except PluginAttributeError: 158 except PluginAttributeError:
159 handler = None 159 handler = None
160 160
161 if handler is not None: 161 if handler is not None:
162 event_handlers.append(handler) 162 event_handlers.append(handler)
163 163
164 return event_handlers 164 return event_handlers
165 165
166 166
167 def send_event(event): 167 def send_event(event):
168 """Function called from outside to process an event 168 """Function called from outside to process an event
169 169
170 @return: a list of messages returned by handlers 170 @return: a list of messages returned by handlers
171 @rtype: list 171 @rtype: list
172 """ 172 """
173 173
174 # A list of messages generated by event handlers, passed back to caller 174 # A list of messages generated by event handlers, passed back to caller
175 msg = [] 175 msg = []
176 cfg = event.request.cfg 176 cfg = event.request.cfg
177 177
178 # Try to handle the event with each available handler (for now) 178 # Try to handle the event with each available handler (for now)
179 for handle in cfg.event_handlers: 179 for handle in cfg.event_handlers:
180 retval = handle(event) 180 retval = handle(event)
181 if retval: 181 if retval:
182 msg.append(retval) 182 msg.append(retval)
183 183
184 return msg 184 return msg
185 185
186 def get_subscribable_events(): 186 def get_subscribable_events():
187 """Create and return a list of user-visible events 187 """Create and return a list of user-visible events
188 188
189 @return: A list of user-visible events described by dictionaries 189 @return: A list of user-visible events described by dictionaries
190 @rtype: dict 190 @rtype: dict
191 """ 191 """
192 defs = globals() 192 defs = globals()
193 subscribable_events = {} 193 subscribable_events = {}
194 194
195 for ev in defs.values(): 195 for ev in defs.values():
196 if type(ev) is type and issubclass(ev, Event) and ev.__dict__.has_key("description"): 196 if type(ev) is type and issubclass(ev, Event) and ev.__dict__.has_key("description"):
197 subscribable_events[ev.__name__] = {'desc': ev.description, 197 subscribable_events[ev.__name__] = {'desc': ev.description,
198 'superuser': ev.req_superuser} 198 'superuser': ev.req_superuser}
199 return subscribable_events 199 return subscribable_events