changeset 3636:4a1813f1cb61

event notifications: send notifies in the language of the message recipient (not of the current wiki user)
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Fri, 23 May 2008 22:59:30 +0200
parents 75db5e7c09e2
children 92d08c1975b0
files MoinMoin/events/emailnotify.py MoinMoin/events/jabbernotify.py MoinMoin/events/notification.py
diffstat 3 files changed, 21 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/events/emailnotify.py	Fri May 23 21:44:42 2008 +0200
+++ b/MoinMoin/events/emailnotify.py	Fri May 23 22:59:30 2008 +0200
@@ -33,7 +33,7 @@
 
     """
     change = notification.page_change_message("page_changed", request, page, email_lang, comment=comment, revisions=revisions)
-    _ = lambda s, wiki=False, r=request, l=email_lang: r.getText(s, wiki=wiki, lang=l)
+    _ = lambda text: request.getText(text, lang=email_lang)
 
     if len(revisions) >= 2:
         querystr = {'action': 'diff',
@@ -104,26 +104,21 @@
 def handle_user_created(event):
     """Sends an email to super users that have subscribed to this event type"""
 
-    emails = []
-    _ = event.request.getText
-    user_ids = getUserList(event.request)
+    request = event.request
+    sitename = request.cfg.sitename
+    from_address = request.cfg.mail_from
     event_name = event.name
-
-    from_address = event.request.cfg.mail_from
     email = event.user.email or u"NOT SET"
-    sitename = event.request.cfg.sitename
     username = event.user.name
 
-    data = notification.user_created_message(event.request, sitename, username, email)
-
+    user_ids = getUserList(request)
     for usr_id in user_ids:
-        usr = User(event.request, id=usr_id)
-
+        usr = User(request, id=usr_id)
         # Currently send this only to super users
         if usr.isSuperUser() and event_name in usr.email_subscribed_events:
-            emails.append(usr.email)
-
-    send_notification(event.request, from_address, emails, data)
+            _ = lambda text: request.getText(text, lang=usr.language)
+            data = notification.user_created_message(request, _, sitename, username, email)
+            send_notification(request, from_address, [usr.email], data)
 
 
 def handle_file_attached(event):
--- a/MoinMoin/events/jabbernotify.py	Fri May 23 21:44:42 2008 +0200
+++ b/MoinMoin/events/jabbernotify.py	Fri May 23 22:59:30 2008 +0200
@@ -132,39 +132,33 @@
 
 def handle_user_created(event):
     """Handles an event sent when a new user is being created"""
-
-    jids = []
-    user_ids = getUserList(event.request)
+    request = event.request
+    sitename = request.cfg.sitename
     event_name = event.name
-
     email = event.user.email or u"NOT SET"
-    sitename = event.request.cfg.sitename
     username = event.user.name
 
-    msg = notification.user_created_message(event.request, sitename, username, email)
-
+    user_ids = getUserList(request)
     for id in user_ids:
-        usr = User(event.request, id=id)
-
+        usr = User(request, id=id)
         # Currently send this only to super users
         if usr.isSuperUser() and usr.jid and event_name in usr.jabber_subscribed_events:
-            jids.append(usr.jid)
-
-    data = {'action': "user_created", 'subject': msg['subject'], 'text': msg['text'],
-            'url_list': []}
-
-    send_notification(event.request, jids, data)
+            _ = lambda text: request.getText(text, lang=usr.language)
+            msg = notification.user_created_message(request, _, sitename, username, email)
+            data = {'action': "user_created", 'subject': msg['subject'], 'text': msg['text'],
+                    'url_list': []}
+            send_notification(request, [usr.jid], data)
 
 
 def page_change(change_type, request, page, subscribers, **kwargs):
     """Sends notification about page being changed in some way"""
-    _ = request.getText
 
     # send notifications to all subscribers
     if subscribers:
         recipients = set()
 
         for lang in subscribers:
+            _ = lambda text: request.getText(text, lang=lang)
             jids = [u.jid for u in subscribers[lang] if u.jid]
             names = [u.name for u in subscribers[lang] if u.jid]
             msg = notification.page_change_message(change_type, request, page, lang, **kwargs)
--- a/MoinMoin/events/notification.py	Fri May 23 21:44:42 2008 +0200
+++ b/MoinMoin/events/notification.py	Fri May 23 22:59:30 2008 +0200
@@ -66,8 +66,7 @@
     @rtype: dict
 
     """
-    _ = request.getText
-    page._ = lambda s, wiki=False, r=request, l=lang: r.getText(s, wiki=wiki, lang=l)
+    _ = lambda text: request.getText(text, lang=lang)
     changes = {'page_name': page.page_name, 'revision': str(page.getRevList()[0])}
 
     if msgtype == "page_changed":
@@ -123,12 +122,11 @@
 
     return changes
 
-def user_created_message(request, sitename, username, email):
+def user_created_message(request, _, sitename, username, email):
     """Formats a message used to notify about accounts being created
 
     @return: a dict containing message body and subject
     """
-    _ = request.getText
     subject = _("New user account created on %(sitename)s") % {'sitename': sitename or "Wiki"}
     text = _("""Dear Superuser, a new user has just been created. Details follow: