changeset 2469:663867be4afc

Add a separate TrivialPageChangedEvent users can subscribe to.
author Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
date Fri, 20 Jul 2007 02:57:25 +0200
parents 4a199a4c5d31
children f15b9bf952d4 4e9370e2e8f1
files MoinMoin/PageEditor.py MoinMoin/events/__init__.py MoinMoin/events/emailnotify.py MoinMoin/events/jabbernotify.py
diffstat 4 files changed, 31 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/PageEditor.py	Fri Jul 20 02:07:09 2007 +0200
+++ b/MoinMoin/PageEditor.py	Fri Jul 20 02:57:25 2007 +0200
@@ -1055,7 +1055,11 @@
             if notify:
                 # send notifications
                 from MoinMoin import events
-                e = events.PageChangedEvent(self.request, self, comment, trivial)
+
+                if trivial:
+                    e = events.TrivialPageChangedEvent(self.request, self, comment)
+                else:
+                    e = events.PageChangedEvent(self.request, self, comment)
                 results = events.send_event(e)
 
                 recipients = set()
--- a/MoinMoin/events/__init__.py	Fri Jul 20 02:07:09 2007 +0200
+++ b/MoinMoin/events/__init__.py	Fri Jul 20 02:57:25 2007 +0200
@@ -41,14 +41,24 @@
 
 class PageChangedEvent(PageEvent):
 
-    description = _(u"""Page has been modified (edit, creation, deletion)""")
+    description = _(u"""Page has been modified""")
     req_superuser = False
 
-    def __init__(self, request, page, comment, trivial):
+    def __init__(self, request, page, comment):
         PageEvent.__init__(self, request)
         self.page = page
         self.comment = comment
-        self.trivial = trivial
+
+
+class TrivialPageChangedEvent(PageEvent):
+
+    description = _(u"Page has been modified in a trivial fashion")
+    req_superuser = False
+
+    def __init__(self, request, page, comment):
+        PageEvent.__init__(self, request)
+        self.page = page
+        self.comment = comment
 
 
 class PageRenamedEvent(PageEvent):
--- a/MoinMoin/events/emailnotify.py	Fri Jul 20 02:07:09 2007 +0200
+++ b/MoinMoin/events/emailnotify.py	Fri Jul 20 02:57:25 2007 +0200
@@ -17,8 +17,8 @@
 from MoinMoin import user
 from MoinMoin.Page import Page
 from MoinMoin.mail import sendmail
-from MoinMoin.events import PageChangedEvent, UserCreatedEvent, FileAttachedEvent
 from MoinMoin.user import User, getUserList
+import MoinMoin.events as ev
 import MoinMoin.events.notification as notification
 
 
@@ -80,7 +80,7 @@
         # send email to all subscribers
         for lang in subscribers:
             users = [u for u in subscribers[lang]
-                     if PageChangedEvent.__name__ in u.email_subscribed_events]
+                     if ev.PageChangedEvent.__name__ in u.email_subscribed_events]
             emails = [u.email for u in users]
             names = [u.name for u in users]
             data = prep_page_changed_mail(request, page, comment, lang, revisions, trivial)
@@ -152,9 +152,11 @@
     if not event.request.cfg.mail_enabled:
         return
 
-    if isinstance(event, PageChangedEvent):
-        return notify_subscribers(event.request, event.page, event.comment, event.trivial)
-    elif isinstance(event, UserCreatedEvent):
+    if isinstance(event, ev.PageChangedEvent):
+        return notify_subscribers(event.request, event.page, event.comment, False)
+    elif isinstance(event, ev.TrivialPageChangedEvent):
+        return notify_subscribers(event.request, event.page, event.comment, True)
+    elif isinstance(event, ev.UserCreatedEvent):
         return handle_user_created(event)
-    elif isinstance(event, FileAttachedEvent):
+    elif isinstance(event, ev.FileAttachedEvent):
         return handle_file_attached(event)
--- a/MoinMoin/events/jabbernotify.py	Fri Jul 20 02:07:09 2007 +0200
+++ b/MoinMoin/events/jabbernotify.py	Fri Jul 20 02:57:25 2007 +0200
@@ -32,7 +32,9 @@
         return
 
     if isinstance(event, ev.PageChangedEvent):
-        return handle_page_changed(event)
+        return handle_page_changed(event, False)
+    elif isinstance(event, ev.TrivialPageChangedEvent):
+        return handle_page_changed(event, True)
     elif isinstance(event, ev.JabberIDSetEvent) or isinstance(event, ev.JabberIDUnsetEvent):
         return handle_jid_changed(event)
     elif isinstance(event, ev.FileAttachedEvent):
@@ -91,12 +93,12 @@
     return notification.Success(names)
 
 
-def handle_page_changed(event):
+def handle_page_changed(event, trivial):
     """ Handles events related to page changes """
     request = event.request
     page = event.page
 
-    subscribers = page.getSubscribers(request, return_users=1, trivial=event.trivial)
+    subscribers = page.getSubscribers(request, return_users=1, trivial=trivial)
     notification.filter_subscriber_list(event, subscribers, True)
     return page_change("page_changed", request, page, subscribers, \
                        revisions=page.getRevList(), comment=event.comment)