Skip to content

Instantly share code, notes, and snippets.

View chronossc's full-sized avatar

Felipe Prenholato chronossc

View GitHub Profile
# coding: utf-8
from ldapdb.models.fields import CharField, ImageField, IntegerField, ListField
import ldapdb.models
class LdapUser(ldapdb.models.Model):
"""
Class for representing an LDAP user entry.
"""
# LDAP meta-data
Index: __init__.py
===================================================================
--- __init__.py (revision 995)
+++ __init__.py (working copy)
@@ -89,10 +89,20 @@
def search_s(self, base, scope, filterstr, attrlist):
cursor = self._cursor()
- results = cursor.connection.search_s(base, scope, filterstr.encode(self.charset), attrlist)
output = []
In [1]: from ldap_connector.models import LdapUser
In [2]:
In [3]: x = LdapUser.objects.filter(username__icontains='teste.ad')
In [4]: for u in x:
...: print u.full_name,u.username,u.email
...:
...:
# coding: utf-8
from ldapdb.models.fields import CharField, ImageField, IntegerField, ListField
import ldapdb.models
class LdapUser(ldapdb.models.Model):
"""
Class for representing an LDAP user entry.
"""
# LDAP meta-data
@chronossc
chronossc / gist:895432
Created March 30, 2011 22:21
ldap_connector.backends
# coding: utf-8
import ldap
from django_auth_ldap.backend import LDAPBackend as _LDAPBackend, _LDAPUser,\
populate_user, populate_user_profile, ldap_settings, User
from rh.models import User, Colaborador
from django.db.models import ObjectDoesNotExist
# The custom backend
class LDAPBackend(_LDAPBackend):
<script type="text/javascript">
$(function(){
$("input[type!=hidden]").each(function(i,obj) {
//console.debug(i,obj)
if ($(obj).attr('id').slice(0,8) == "id_form2") {
hidden_name = $(obj).attr('name').replace('2','1')
obj_hidden = $("input[name="+hidden_name+"]") // so we get form 1 value field
(p2)felipe@PLAPSTMD142:~/projects/p2/portal$ m shell
Traceback (most recent call last):
File "manage.py", line 11, in <module>
execute_manager(settings)
File "/home/felipe/projects/p2/lib/python2.6/site-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/home/felipe/projects/p2/lib/python2.6/site-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/felipe/projects/p2/lib/python2.6/site-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
# coding: utf-8
from ldapdb.router import is_ldap_model, Router as _Router
class Router(object):
def db_for_read(self, model, **hints):
if is_ldap_model(model):
return 'ldap_gold'
return None
DATABASES = {
'ldap_srv1': { # router force to this one
'ENGINE': 'ldapdb.backends.ldap',
'HOST': "ldap://srv1.corp",
'USER': "ldap@srv1.corp",
'PASSWORD': "pdg@114",
'BASE_DN': 'DC=srv1,DC=corp',
},
'ldap_srv2': {
'ENGINE': 'ldapdb.backends.ldap',
class Router(object):
def db_for_read(self, model, **hints):
return getattr(model,'using',None)
def db_for_write(self, model, **hints):
return getattr(model,'using',None)