Skip to content

Instantly share code, notes, and snippets.

@etianen
Created May 3, 2017 13:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save etianen/1d5d98e2441c26d11e7bdba3e9a3a17c to your computer and use it in GitHub Desktop.
Save etianen/1d5d98e2441c26d11e7bdba3e9a3a17c to your computer and use it in GitHub Desktop.
# your_project/your_app/ldap.py
import django_python3_ldap.utils.clean_user_data
def clean_user_data(model_fields):
"""
Transforms the user data loaded from
LDAP into a form suitable for creating a user.
"""
# Call the default handler.
model_fields = django_python3_ldap.utils.clean_user_data(model_fields)
# Add our own data in.
model_fields["is_staff"] = True
model_fields["is_superuser"] = True
return model_fields
# settings.py
AUTH_CLEAN_USER_DATA = "your_project.your_app.clean_user_data"
@tazou
Copy link

tazou commented May 3, 2017

Hi, thanks :)

Is it not LDAP_AUTH_CLEAN_USER_DATA instead of AUTH_CLEAN_USER_DATA in settings.py ?

Do you know if my ldap.py is in the right directory ?
I have this tree :
capture du 2017-05-03 16-14-48

And is enough to put ldap.py file in the directory c2i to be taken into account ?

Last question, regarding my tree, is this var OK ?
LDAP_AUTH_CLEAN_USER_DATA = "c2i.clean_user_data"

With all of this, when I try to login, I have this error :

ImportError at /admin/login/

Module "c2i" does not define a "clean_user_data" attribute/class

Request Method: 	POST
Request URL: 	http://127.0.0.1:8000/admin/login/?next=/admin/
Django Version: 	1.11
Exception Type: 	ImportError
Exception Value: 	

Module "c2i" does not define a "clean_user_data" attribute/class

Exception Location: 	/home/gduale/py361-django-ldap/lib/python3.6/site-packages/Django-1.11-py3.6.egg/django/utils/module_loading.py in import_string, line 23
Python Executable: 	/home/gduale/py361-django-ldap/bin/python
Python Version: 	3.6.1
Python Path: 	

['/home/gduale/django-projects/test-c2i/c2i',
 '/home/gduale/make_python/python-3.6.1/lib/python36.zip',
 '/home/gduale/make_python/python-3.6.1/lib/python3.6',
 '/home/gduale/make_python/python-3.6.1/lib/python3.6/lib-dynload',
 '/home/gduale/py361-django-ldap/lib/python3.6/site-packages',
 '/home/gduale/py361-django-ldap/lib/python3.6/site-packages/django_python3_ldap-0.9.14-py3.6.egg',
 '/home/gduale/py361-django-ldap/lib/python3.6/site-packages/ldap3-2.2.3-py3.6.egg',
 '/home/gduale/py361-django-ldap/lib/python3.6/site-packages/Django-1.11-py3.6.egg',
 '/home/gduale/py361-django-ldap/lib/python3.6/site-packages/pyasn1-0.2.3-py3.6.egg',
 '/home/gduale/py361-django-ldap/lib/python3.6/site-packages/pytz-2017.2-py3.6.egg']

Server time: 	Wed, 3 May 2017 14:20:17 +0000

Regards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment