changeset 787:7a51d13c9bc3 pytest2

user: simplify some code, do less, only get_items_by_filter is using search_items
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 28 Aug 2011 16:02:54 +0200
parents bb40c019139c
children 9fe3154e6ad0
files MoinMoin/user.py
diffstat 1 files changed, 11 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/user.py	Sun Aug 28 15:25:58 2011 +0200
+++ b/MoinMoin/user.py	Sun Aug 28 16:02:54 2011 +0200
@@ -105,19 +105,18 @@
     return [item.name for item in all_users]
 
 
-def get_by_filter(key, value):
+def get_items_by_filter(key, value):
     """ Searches for an user with a given filter """
     from MoinMoin.storage.terms import ItemMetaDataMatch
     items = get_user_backend().search_items(ItemMetaDataMatch(key, value))
-    users = [User(item.name) for item in items]
-    return users
+    return list(items)
 
 
 def get_by_email_address(email_address):
     """ Searches for an user with a particular e-mail address and returns it. """
-    users = get_by_filter('email', email_address)
-    if len(users) > 0:
-        return users[0]
+    items = get_items_by_filter('email', email_address)
+    if items:
+        return User(items[0].name)
 
 def get_by_openid(openid):
     """
@@ -128,9 +127,9 @@
     :returns: the user whose openid is this one
     :rtype: user object or None
     """
-    users = get_by_filter('openid', openid)
-    if len(users) > 0:
-        return users[0]
+    items = get_items_by_filter('openid', openid)
+    if items:
+        return User(items[0].name)
 
 def getUserId(searchName):
     """ Get the user ID for a specific user NAME.
@@ -139,15 +138,9 @@
     :rtype: string
     :returns: the corresponding user ID or None
     """
-    from MoinMoin.storage.terms import ItemMetaDataMatch
-    try:
-        backend = get_user_backend()
-        for user in backend.search_items(ItemMetaDataMatch('name', searchName)):
-            return user.name
-        return None
-    except IndexError:
-        return None
-
+    items = get_items_by_filter('name', searchName)
+    if items:
+        return items[0].name
 
 def get_editor(userid, addr, hostname):
     """ Return a tuple of type id and string or Page object