This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django_python3_ldap.ldap import connection | |
with connection() as c: | |
print(c.get_user(username="foo")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django_python3_ldap import ldap | |
from django.contrib.auth.decorators import login_required | |
@login_required | |
def ldap_seach(request): | |
# Because of login_required, this view is protected by the Django login screen. | |
# request.user will be the logged-in user. | |
if request.method == "POST": | |
# The user has submitted the search form of the user to look up. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ldap3.Connection( | |
ldap3.Server( | |
"ldap://msldap.uct.ac.za", | |
allowed_referral_hosts=[("*", True)], | |
), | |
user="01421894@wf.uct.ac.za", | |
password="password", | |
auto_bind=ldap3.AUTO_BIND_NO_TLS, | |
raise_exceptions=True, | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class YourSearchAdapter(watson.SearchAdapter): | |
def get_title(self, obj): | |
return super().get_title(obj).lower() | |
def get_description(self, obj): | |
return super().get_description(obj).lower() | |
def get_content(self, obj): | |
return super().get_content(obj).lower() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.apps import AppConfig | |
from watson import search as watson | |
search_engine_1 = watson.SearchEngine("engine_1") | |
search_engine_2 = watson.SearchEngine("engine_2") | |
class YourAppConfig(AppConfig): | |
name = "customer" | |
def ready(self): | |
search_engine_1.register(self.get_model("ModelA")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.apps import AppConfig | |
from watson import search as watson | |
search_engine_1 = watson.SearchEngine("engine_1") | |
search_engine_2 = watson.SearchEngine("engine_2") | |
class YourAppConfig(AppConfig): | |
name = "customer" | |
def ready(self): | |
search_engine_1.register(self.get_model("ModelA")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" ldap_auth.py (custom methods for django_python3_ldap) | |
Create three additional groups in LDAP directory (e.g w/ prefix "django_"): | |
* cn=django_my_django_project,ou=groups,dc=example.com,dc=com | |
* cn=django_my_django_project_staff,ou=groups,dc=example.com,dc=com | |
* cn=django_my_django_project_superuser,ou=groups,dc=example.com,dc=com | |
1) "django_my_django_project" | |
Add all users to this group that should be able to use the Django APP. | |
The users will then be able to authenticate and their attributes will be synched. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Runs a per-page init function. | |
* | |
* The init function is chosen via the `page` config setting. | |
* | |
* This has to be defined in a separate module, since RequireJS | |
* does not allow passing config to the main module. | |
*/ | |
define(["module"], function(module) { | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Node(models.Model): | |
parent = models.ForeignKey("self", blank=True, null=True) | |
reversion.register(Node) | |
with reversion.create_revision(): | |
p = Node.objects.create() # Version saved. | |
with reversion.create_revision(): | |
c = Node.objects.create() # Version saved. |
NewerOlder