mango r208 - in branches/django: . mango
- From: ovitters svn gnome org
- To: svn-commits-list gnome org,gnome-sysadmin gnome org
- Subject: mango r208 - in branches/django: . mango
- Date: Sat, 21 Jun 2008 22:09:09 +0000 (UTC)
Author: ovitters
Date: Sat Jun 21 22:09:08 2008
New Revision: 208
URL: http://svn.gnome.org/viewvc/mango?rev=208&view=rev
Log:
* mango/models.py: Add LdapUtil singleton. Maintains a single
connection to the LDAP database.
* mango/views.py: Make use of the LDAP singleton.
Modified:
branches/django/ (props changed)
branches/django/ChangeLog
branches/django/mango/models.py
branches/django/mango/views.py
Modified: branches/django/mango/models.py
==============================================================================
--- branches/django/mango/models.py (original)
+++ branches/django/mango/models.py Sat Jun 21 22:09:08 2008
@@ -8,6 +8,8 @@
# into your database.
from django.db import models
+from django.conf import settings
+import ldap
class AccountRequest(models.Model):
id = models.AutoField(primary_key=True)
@@ -73,3 +75,32 @@
class Meta:
db_table = u'webmirrors'
+class LdapUtil(object):
+
+ handle = None
+ instance = None
+
+ @classmethod
+ def singleton(cls):
+ if cls.instance is None:
+ try:
+ cls.instance = cls()
+ except:
+ return None
+
+ return cls.instance
+
+ def __init__(self):
+ l = ldap.initialize(settings.MANGO_CFG['ldap_url'])
+ l.protocol_version = ldap.VERSION3
+ try:
+ l.simple_bind_s(settings.MANGO_CFG['ldap_binddn'], settings.MANGO_CFG['ldap_bindpw'])
+ except:
+ return None
+
+ self.__class__.handle = l
+
+ def __del__(self):
+ if self.__class__.handle is not None:
+ self.__class__.handle..unbind_s()
+
Modified: branches/django/mango/views.py
==============================================================================
--- branches/django/mango/views.py (original)
+++ branches/django/mango/views.py Sat Jun 21 22:09:08 2008
@@ -1,4 +1,4 @@
-from django.http import HttpResponse
+from django.http import HttpResponse, Http404, HttpResponseServerError
from django.conf import settings
import datetime
@@ -42,8 +42,9 @@
def list_users(request):
- l = ldap.initialize(settings.MANGO_CFG['ldap_url'])
-# l.simple_bind("cn=Manager,dc=gnome,dc=org")
+ l = models.LdapUtil().handle
+ if not l:
+ return HttpResponseServerError('Cannot connect to LDAP?')
filter = '(objectClass=posixAccount)'
stuff = l.search_s(settings.MANGO_CFG['ldap_users_basedn'],
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]