[Moin-devel] CVS: MoinMoin PageEditor.py,1.9,1.10

J?rgen Hermann jhermann at users.sourceforge.net
Tue May 7 10:06:03 EDT 2002


Update of /cvsroot/moin/MoinMoin
In directory usw-pr-cvs1:/tmp/cvs-serv32198/MoinMoin

Modified Files:
	PageEditor.py 
Log Message:
DeletePage offers a textentry field for an optional comment;
Email notifications are sent in the user's language, if known from
the preferences (adapted from a patch by Lelé)


Index: PageEditor.py
===================================================================
RCS file: /cvsroot/moin/MoinMoin/PageEditor.py,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -r1.9 -r1.10
*** PageEditor.py	2 May 2002 19:13:07 -0000	1.9
--- PageEditor.py	7 May 2002 17:05:22 -0000	1.10
***************
*** 12,16 ****
  from MoinMoin import caching, config, user, util, wikiutil, webapi
  from MoinMoin.Page import Page
! from MoinMoin.i18n import _
  
  
--- 12,16 ----
  from MoinMoin import caching, config, user, util, wikiutil, webapi
  from MoinMoin.Page import Page
! from MoinMoin.i18n import _, getText
  
  
***************
*** 201,209 ****
  
  
!     def deletePage(self, request):
          """Delete the page (but keep the backups)"""
          # First save a final backup copy of the current page
          # (recreating the page allows access to the backups again)
!         self.save_text(request, "deleted", '0')
  
          # Then really delete it
--- 201,209 ----
  
  
!     def deletePage(self, request, comment=None):
          """Delete the page (but keep the backups)"""
          # First save a final backup copy of the current page
          # (recreating the page allows access to the backups again)
!         self.save_text(request, "deleted", '0', comment=comment or '')
  
          # Then really delete it
***************
*** 221,224 ****
--- 221,267 ----
  
  
+     def _sendNotification(self, request, comment, emails, email_lang, oldversions):
+         """ Send notification email for a single language.
+ 
+             Returns sendmail result.
+         """
+         _ = lambda s, l=email_lang: getText(s, lang=l)
+ 
+         mailBody = _("Dear Wiki user,\n\n"
+             'You have subscribed to a wiki page or wiki category on "%(sitename)s" for change notification.\n\n'
+             "The following page has been changed by %(editor)s:\n"
+             "%(pagelink)s\n\n") % {
+                 'editor': request.user.name or os.environ.get('REMOTE_ADDR', _("<unknown>")),
+                 'pagelink': webapi.getQualifiedURL(self.url()),
+                 'sitename': config.sitename or webapi.getBaseURL(),
+         }
+ 
+         if comment:
+             mailBody = mailBody + \
+                 _("The comment on the change is:\n%(comment)s\n\n") % locals()
+ 
+         # append a diff
+         if not oldversions:
+             mailBody = mailBody + \
+                 _("No older revisions of the page stored, diff not available.")
+         else:
+             rc, page_file, backup_file, lines = wikiutil.pagediff(self.page_name, oldversions[0])
+             if lines and len(lines) > 2:
+                 mailBody = "%s%s\n%s" % (
+                     mailBody, ("-" * 78), string.join(lines[2:], ''))
+             else:
+                 mailBody = mailBody + _("No differences found!\n")
+                 if rc:
+                     mailBody = mailBody + '\n\n' + \
+                         _('The external diff utility returned with error code %(rc)s!') % locals()
+ 
+         return util.sendmail(emails,
+             _('[%(sitename)s] Update of "%(pagename)s"') % {
+                 'sitename': config.sitename or "Wiki",
+                 'pagename': self.page_name,
+             },
+             mailBody, mail_from=request.user.email)
+ 
+ 
      def _notifySubscribers(self, request, comment):
          """ Send email to all subscribers of this page.
***************
*** 237,241 ****
          # the user is not the current editor
          userlist = user.getUserList()
!         emails = []
          for uid in userlist:
              if uid == request.user.id: continue # no self notification
--- 280,284 ----
          # the user is not the current editor
          userlist = user.getUserList()
!         emails = {}
          for uid in userlist:
              if uid == request.user.id: continue # no self notification
***************
*** 243,293 ****
              if not subscriber.email: continue # skip empty email address
  
!             if subscriber.isSubscribedTo(pageList):
!                 emails.append(subscriber.email)
  
          if emails:
-             # send email to all subscribers; note that text must be in
-             # English for all users, since currently we cannot (easily)
-             # send the text in the recipient's language.
-             # !!! TODO: make this possible
-             mailBody = ("Dear Wiki user,\n\n"
-                 'You have subscribed to a wiki page or wiki category on "%(sitename)s" for change notification.\n\n'
-                 "The following page has been changed by %(editor)s:\n"
-                 "%(pagelink)s\n\n") % {
-                     'editor': request.user.name or os.environ.get('REMOTE_ADDR', "<unknown>"),
-                     'pagelink': webapi.getQualifiedURL(self.url()),
-                     'sitename': config.sitename or webapi.getBaseURL(),
-             }
- 
-             if comment:
-                 mailBody = mailBody + \
-                     "The comment on the change is:\n%s\n\n" % comment
- 
              # get a list of old revisions, and append a diff
              oldversions = wikiutil.getBackupList(config.backup_dir, self.page_name)
!             if not oldversions:
!                 mailBody = mailBody + \
!                     "No older revisions of the page stored, diff not available."
!             else:
!                 rc, page_file, backup_file, lines = wikiutil.pagediff(self.page_name, oldversions[0])
!                 if lines and len(lines) > 2:
!                     mailBody = "%s%s\n%s" % (
!                         mailBody, ("-" * 78), string.join(lines[2:], ''))
!                 else:
!                     mailBody = mailBody + "No differences found!\n"
!                     if rc:
!                         mailBody = mailBody + '\n\n' + \
!                             _('The external diff utility returned with error code %(rc)s!') % locals()
! 
!             msg = _('\n'
!                     'Sent a mail notification to these addresses: %s\n'
!                     '<br>Result was: ') % string.join(emails, ", ")
!             msg = msg + util.sendmail(emails,
!                 '[%(sitename)s] Update of "%(pagename)s"' % {
!                     'sitename': config.sitename or "Wiki",
!                     'pagename': self.page_name,
!                 },
!                 mailBody, mail_from=request.user.email)
!             return msg
  
          return _('Nobody subscribed to this page, no mail sent.')
--- 286,306 ----
              if not subscriber.email: continue # skip empty email address
  
!             if subscriber.isSubscribedTo(pageList):                
!                 lang = subscriber.language or 'en'
!                 if not emails.has_key(lang): emails[lang] = []
!                 emails[lang].append(subscriber.email) 
  
          if emails:
              # get a list of old revisions, and append a diff
              oldversions = wikiutil.getBackupList(config.backup_dir, self.page_name)
! 
!             # send email to all subscribers 
!             results = [_('Status of sending notification mails:')]
!             for lang in emails.keys(): 
!                 status = self._sendNotification(request, comment, emails[lang], lang, oldversions)
!                 recipients = string.join(emails[lang], ", ")
!                 results.append(_('[%(lang)s] %(recipients)s: %(status)s') % locals())
! 
!             return string.join(results, '<br>')
  
          return _('Nobody subscribed to this page, no mail sent.')





More information about the Moin-devel mailing list