mango r213 - in branches/django: . mango



Author: ovitters
Date: Sat Jun 21 23:45:51 2008
New Revision: 213
URL: http://svn.gnome.org/viewvc/mango?rev=213&view=rev

Log:
	* mango/models.py (LdapObject): New class that can search for
	something in LDAP. Is not very smart atm.
	(Users): Uses LdapObject to store a user in.


Modified:
   branches/django/   (props changed)
   branches/django/ChangeLog
   branches/django/mango/models.py

Modified: branches/django/mango/models.py
==============================================================================
--- branches/django/mango/models.py	(original)
+++ branches/django/mango/models.py	Sat Jun 21 23:45:51 2008
@@ -100,3 +100,39 @@
 
         self.__class__.handle = l
 
+
+class LdapObject(object):
+    
+    BASEDN = None
+    MULTI_ATTRS = set(('objectClass'))
+
+    def __init__(self, dn, attrs):
+        for k, i in attrs.items():
+            if k in self.MULTI_ATTRS:
+                self.__dict__[k] = i
+            else:
+                self.__dict__[k] = i[0]
+        self.dn = dn
+
+    @classmethod
+    def search(cls, filter):
+        l = LdapUtil.singleton().handle
+        
+        base = cls.BASEDN
+
+        results = l.search_s(base, ldap.SCOPE_SUBTREE, filter, None)
+
+        items = []
+
+        for result in results:
+            items.append(cls(result[0], result[1]))
+
+        return items
+
+
+class Users(LdapObject):
+
+    BASEDN = settings.MANGO_CFG['ldap_users_basedn']
+    MULTI_ATTRS = set(('authorizedKey','objectClass'))
+
+



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]