Skip to content

Instantly share code, notes, and snippets.

View etianen's full-sized avatar

Dave Hall etianen

View GitHub Profile
from django_python3_ldap.ldap import connection
with connection() as c:
print(c.get_user(username="foo"))
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.
import qualified Data.Map as Map
{- Supported HTTP methods. -}
data HttpMethod = GET | POST deriving (Read, Show)
{- A parsed HTTP request. --}
# 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.
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,
)
SELECT
(
IF (
(
SELECT COUNT(*)
FROM `people_person_contacts`
WHERE `from_person_id` = 12895 AND `to_person_id` = `people_person`.`id`
),
1,
IF (
SELECT DISTINCT
`people_person`.`id`,
`people_person`.`date_created`,
`people_person`.`date_modified`,
`people_person`.`access`,
`people_person`.`thumbnail`,
`people_person`.`description`,
`people_person`.`short_description`,
`people_person`.`title`,
`people_person`.`first_name`,
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()
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"))
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"))