changeset 3513:7bfd4232cfb7

builtin userprefs plugins: return appropriate message class
author Johannes Berg <johannes AT sipsolutions DOT net>
date Sat, 19 Apr 2008 11:23:50 +0200
parents 3fc77153629a
children 6adf6716f098
files MoinMoin/userprefs/changepass.py MoinMoin/userprefs/notification.py MoinMoin/userprefs/oid.py MoinMoin/userprefs/prefs.py MoinMoin/userprefs/suid.py
diffstat 5 files changed, 28 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/userprefs/changepass.py	Sat Apr 19 11:03:11 2008 +0200
+++ b/MoinMoin/userprefs/changepass.py	Sat Apr 19 11:23:50 2008 +0200
@@ -48,20 +48,20 @@
 
         # Check if password is given and matches with password repeat
         if password != password2:
-            return _("Passwords don't match!")
+            return 'error', _("Passwords don't match!")
         if not password:
-            return _("Please specify a password!")
+            return 'error', _("Please specify a password!")
 
         pw_checker = request.cfg.password_checker
         if pw_checker:
             pw_error = pw_checker(request.user.name, password)
             if pw_error:
-                return _("Password not acceptable: %s") % pw_error
+                return 'error', _("Password not acceptable: %s") % pw_error
 
         try:
             self.request.user.enc_password = user.encodePassword(password)
             self.request.user.save()
-            return _("Your password has been changed.")
+            return 'info', _("Your password has been changed.")
         except UnicodeError, err:
             # Should never happen
             return "Can't encode password: %s" % str(err)
--- a/MoinMoin/userprefs/notification.py	Sat Apr 19 11:03:11 2008 +0200
+++ b/MoinMoin/userprefs/notification.py	Sat Apr 19 11:23:50 2008 +0200
@@ -71,7 +71,7 @@
         # save data
         theuser.save()
 
-        return _("Notification settings saved!")
+        return 'info', _("Notification settings saved!")
 
 
     def handle_form(self):
--- a/MoinMoin/userprefs/oid.py	Sat Apr 19 11:03:11 2008 +0200
+++ b/MoinMoin/userprefs/oid.py	Sat Apr 19 11:23:50 2008 +0200
@@ -49,10 +49,10 @@
             if name in self.request.form:
                 openids.remove(oid)
         if not openids and len(self.request.cfg.auth) == 1:
-            return _("Cannot remove all OpenIDs.")
+            return 'error', _("Cannot remove all OpenIDs.")
         self.request.user.openids = openids
         self.request.user.save()
-        return _("The selected OpenIDs have been removed.")
+        return 'info', _("The selected OpenIDs have been removed.")
 
     def _handle_add(self):
         _ = self.request.getText
@@ -60,23 +60,23 @@
 
         openid_id = request.form.get('openid_identifier', [''])[0]
         if not openid_id:
-            return _("No OpenID.")
+            return 'error', _("No OpenID given.")
 
         if (hasattr(self.request.user, 'openids') and
             openid_id in request.user.openids):
-            return _("OpenID is already present.")
+            return 'error', _("OpenID is already present.")
 
         oidconsumer = consumer.Consumer(request.session,
                                         MoinOpenIDStore(self.request))
         try:
             oidreq = oidconsumer.begin(openid_id)
         except HTTPFetchingError:
-            return _('Failed to resolve OpenID.')
+            return 'error', _('Failed to resolve OpenID.')
         except DiscoveryFailure:
-            return _('OpenID discovery failure, not a valid OpenID.')
+            return 'error', _('OpenID discovery failure, not a valid OpenID.')
         else:
             if oidreq is None:
-                return _("No OpenID.")
+                return 'error', _("No OpenID given.") # ??
 
             qstr = wikiutil.makeQueryString({'action': 'userprefs',
                                              'handler': 'oid',
@@ -107,25 +107,25 @@
         return_to = request.getQualifiedURL(request.page.url(request, qstr))
         info = oidconsumer.complete(query, return_to=return_to)
         if info.status == consumer.FAILURE:
-            return _('OpenID error: %s.') % info.message
+            return 'error', _('OpenID error: %s.') % info.message
         elif info.status == consumer.CANCEL:
-            return _('Verification canceled.')
+            return 'info', _('Verification canceled.')
         elif info.status == consumer.SUCCESS:
             if not hasattr(self.request.user, 'openids'):
                 request.user.openids = []
 
             if info.identity_url in request.user.openids:
-                return _("OpenID is already present.")
+                return 'error', _("OpenID is already present.")
 
             if user.getUserIdByOpenId(request, info.identity_url):
-                return _("This OpenID is already used for another account.")
+                return 'error', _("This OpenID is already used for another account.")
 
             # all fine
             request.user.openids.append(info.identity_url)
             request.user.save()
-            return _("OpenID added successfully.")
+            return 'info', _("OpenID added successfully.")
         else:
-            return _('OpenID failure.')
+            return 'error', _('OpenID failure.')
 
 
     def handle_form(self):
--- a/MoinMoin/userprefs/prefs.py	Sat Apr 19 11:03:11 2008 +0200
+++ b/MoinMoin/userprefs/prefs.py	Sat Apr 19 11:23:50 2008 +0200
@@ -70,7 +70,7 @@
 
             # Don't allow changing the name to an invalid one
             if not user.isValidName(self.request, new_name):
-                return _("""Invalid user name {{{'%s'}}}.
+                return 'error', _("""Invalid user name {{{'%s'}}}.
 Name may contain any Unicode alpha numeric character, with optional one
 space between words. Group page name is not allowed.""", wiki=True) % wikiutil.escape(new_name)
 
@@ -78,10 +78,10 @@
             # Name required to be unique. Check if name belong to another user.
             existing_id = user.getUserId(self.request, new_name)
             if existing_id is not None and existing_id != self.request.user.id:
-                return _("This user name already belongs to somebody else.")
+                return 'error', _("This user name already belongs to somebody else.")
 
             if not new_name:
-                return _("Empty user name. Please enter a user name.")
+                return 'error', _("Empty user name. Please enter a user name.")
 
             # done sanity checking the name, set it
             request.user.name = new_name
@@ -94,14 +94,14 @@
 
             # Require email
             if not new_email and 'email' not in self.request.cfg.user_form_remove:
-                return _("Please provide your email address. If you lose your"
-                         " login information, you can get it by email.")
+                return 'error', _("Please provide your email address. If you lose your"
+                                  " login information, you can get it by email.")
 
             # Email should be unique - see also MoinMoin/script/accounts/moin_usercheck.py
             if new_email and self.request.cfg.user_email_unique:
                 other = user.get_by_email_address(self.request, new_email)
                 if other is not None and other.id != self.request.user.id:
-                    return _("This email already belongs to somebody else.")
+                    return 'error', _("This email already belongs to somebody else.")
 
             # done checking the email, set it
             request.user.email = new_email
@@ -117,7 +117,7 @@
             if new_jid and self.request.cfg.user_jid_unique:
                 other = user.get_by_jabber_id(self.request, new_jid)
                 if other is not None and other.id != request.user.id:
-                    return _("This jabber id already belongs to somebody else.")
+                    return 'error', _("This jabber id already belongs to somebody else.")
 
             if jid_changed:
                 set_event = events.JabberIDSetEvent(self.request, new_jid)
@@ -165,7 +165,7 @@
             request.user.theme_name = theme_name
             if self.request.loadTheme(theme_name) > 0:
                 theme_name = wikiutil.escape(theme_name)
-                return _("The theme '%(theme_name)s' could not be loaded!") % locals()
+                return 'error', _("The theme '%(theme_name)s' could not be loaded!") % locals()
 
         # try to get the (optional) preferred language
         request.user.language = form.get('language', [''])[0]
--- a/MoinMoin/userprefs/suid.py	Sat Apr 19 11:03:11 2008 +0200
+++ b/MoinMoin/userprefs/suid.py	Sat Apr 19 11:23:50 2008 +0200
@@ -42,10 +42,10 @@
             and self.request.request_method == 'POST'):
             uid = form.get('selected_user', [''])[0]
             if not uid:
-                return _("No user selected")
+                return 'error', _("No user selected")
             theuser = user.User(self.request, uid, auth_method='setuid')
             if not theuser or not theuser.exists():
-                return _("No user selected")
+                return 'error', _("No user selected")
             # set valid to True so superusers can even switch
             # to disable accounts
             theuser.valid = True