changeset 2109:b39379ab47d3

Send notifications when page is deleted + some small fixes.
author Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
date Thu, 07 Jun 2007 18:35:51 +0200
parents c0c7c4cd4eee
children 1ede132a9d38
files MoinMoin/PageEditor.py MoinMoin/events/JabberNotification.py MoinMoin/events/__init__.py MoinMoin/events/messages.py
diffstat 4 files changed, 78 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/PageEditor.py	Thu Jun 07 18:09:43 2007 +0200
+++ b/MoinMoin/PageEditor.py	Thu Jun 07 18:35:51 2007 +0200
@@ -25,6 +25,7 @@
 from MoinMoin.logfile import editlog, eventlog
 from MoinMoin.util import filesys, timefuncs, web
 from MoinMoin.mail import sendmail
+from MoinMoin.events import PageDeletedEvent, send_event
 
 # used for merging
 conflict_markers = ("\n---- /!\\ '''Edit conflict - other version:''' ----\n",
@@ -645,6 +646,9 @@
             raise self.AccessDenied, msg
 
         try:
+            event = PageDeletedEvent(request, self, comment)
+            send_event(event)
+            
             msg = self.saveText(u"deleted\n", 0, comment=comment or u'', index=1, deleted=True)
             msg = msg.replace(
                 _("Thank you for your changes. Your attention to detail is appreciated."),
--- a/MoinMoin/events/JabberNotification.py	Thu Jun 07 18:09:43 2007 +0200
+++ b/MoinMoin/events/JabberNotification.py	Thu Jun 07 18:35:51 2007 +0200
@@ -16,6 +16,7 @@
 from MoinMoin.events import *
 from MoinMoin.events.messages import page_changed_notification
 from MoinMoin.events.messages import file_attached_notification
+from MoinMoin.events.messages import page_deleted_notification
 
 
 # XML RPC Server object used to communicate with notification bot
@@ -41,6 +42,8 @@
         return handle_jid_changed(event)
     elif isinstance(event, FileAttachedEvent):
         return handle_file_attached(event)
+    elif isinstance(event, PageDeletedEvent):
+        return handle_page_deleted(event)
     
 
 def handle_jid_changed(event):
@@ -95,7 +98,7 @@
 
     # No notifications sent, no message.
     return ''
-        
+
         
 def handle_page_changed(event):
     """ Handles events related to page changes """
@@ -104,7 +107,6 @@
     trivial = event.trivial
     comment = event.comment
     page = event.page
-    cfg = request.cfg
     
     _ = request.getText
     
@@ -131,6 +133,40 @@
     # No notifications sent, no message.
     return ''
 
+
+def handle_page_deleted(event):
+    """Handles event sent when a page is deleted"""
+    
+    request = event.request
+    comment = event.comment
+    page = event.page
+    
+    _ = request.getText
+    
+    subscribers = page.getSubscribers(request, return_users=1)
+    if subscribers:
+        # get a list of old revisions, and append a diff
+        revisions = page.getRevList()
+        
+        # send notifications to all subscribers
+        results = [_('Status of sending notifications:')]
+        for lang in subscribers:
+            jids = [u.jid for u in subscribers[lang]]
+            names = [u.name for u in subscribers[lang]]
+            msg = page_deleted_notification(request, page, comment, lang)
+            jabberok, status = send_notification(request, jids, msg)
+            recipients = ", ".join(names)
+            results.append(_('[%(lang)s] %(recipients)s: %(status)s') % {
+                'lang': lang, 'recipients': recipients, 'status': status})
+
+        # Return notifications sent results. Ignore trivial - we don't have
+        # to lie. If notification was sent, just tell about it.
+        return '<p>\n%s\n</p> ' % '<br>'.join(results)
+
+    # No notifications sent, no message.
+    return ''
+
+
 def send_notification(request, jids, message):
     """ Send notifications for a single language.
 
--- a/MoinMoin/events/__init__.py	Thu Jun 07 18:09:43 2007 +0200
+++ b/MoinMoin/events/__init__.py	Thu Jun 07 18:35:51 2007 +0200
@@ -43,8 +43,14 @@
         
 class PageRenamedEvent(PageEvent):
     pass
+
+
 class PageDeletedEvent(PageEvent):
-    pass
+    def __init__(self, request, page, comment):
+        PageEvent.__init__(self, request)
+        self.request = request
+        self.page = page
+        self.comment = comment
 
 
 class FileAttachedEvent(PageEvent):
--- a/MoinMoin/events/messages.py	Thu Jun 07 18:09:43 2007 +0200
+++ b/MoinMoin/events/messages.py	Thu Jun 07 18:35:51 2007 +0200
@@ -15,7 +15,7 @@
 
 
 def page_changed_notification(request, page, comment, lang, revisions, trivial):
-    """ Prepare a notification text for a single language
+    """ Prepare a page change notification text for a single language
 
     @param comment: editor's comment given when saving the page
     @param lang: language of notifications
@@ -64,17 +64,43 @@
             
     return messageBody
 
+def page_deleted_notification(request, page, comment, lang):
+    """ Prepare a page deletion notification text for a single language """
+    
+    _ = request.getText
+    page._ = lambda s, formatted=True, r=request, l=lang: r.getText(s, formatted=formatted, lang=l)
+    
+    pagelink = request.getQualifiedURL(page.url(request, {}, relative=False))
+    
+    messageBody = _("Dear wiki user,\n\n"
+        'You have subscribed to a wiki page "%(sitename)s" for change notification.\n\n'
+        "The following page has been deleted by %(editor)s:\n"
+        "%(pagelink)s\n\n", formatted=False) % {
+            'editor': page.uid_override or user.getUserIdentification(request),
+            'pagelink': pagelink,
+            'sitename': page.cfg.sitename or request.getBaseURL(),
+    }
+        
+    if comment:
+        messageBody = messageBody + \
+            _("The comment on the change is:\n%(comment)s", formatted=False) % {'comment': comment}
+        
+    return messageBody
+                                                                          
+
 def file_attached_notification(request, pagename, lang, attach_name, attach_size):
+    """ Prepare an attachment added notification text for a single language """
     
     _ = request.getText
     page = Page(request, pagename)
     pagelink = request.getQualifiedURL(page.url(request, {}, relative=False))
     attachlink = request.getBaseURL() + getAttachUrl(pagename, attach_name, request)
     
-    messageBody = _("Dear Wiki user.\n\n"
+    page._ = lambda s, formatted=True, r=request, l=lang: r.getText(s, formatted=formatted, lang=l)
+    
+    messageBody = _("Dear Wiki user,\n\n"
         'You have subscribed to a wiki page "%(sitename)s" for change notification.\n\n'
         "An attachment has been added to the following page by %(editor)s:\n"
-        "%(pagelink)s\n\n"
         "Following detailed information is available:\n"
         "Attachment name: %(attach_name)s\n"
         "Attachment size: %(attach_size)s\n"