Skip to main content
https://badge.fury.io/py/django-genomix-users.svg https://travis-ci.org/chopdgd/django-genomix-users.svg?branch=develop https://codecov.io/gh/chopdgd/django-genomix-users/branch/develop/graph/badge.svg Updates Python 3

Core library for Nexus django applications that require User accounts

Documentation

The full documentation is at https://django-genomix-users.readthedocs.io.

Quickstart

Install django-genomix-users:

pip install django-genomix-users

Make the following changes to INSTALLED_APPS in settings.py file:

INSTALLED_APPS = (
    ...
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.staticfiles',
    ...
    'rest_framework',
    'rest_framework.authtoken',
    'rest_auth',
    'django_filters',
    ...
    'django_python3_ldap',
    ...
    'genomix_users',
    ...
)

Add django-genomix-users’s URL patterns:

from genomix_users import urls as genomix_users_urls


urlpatterns = [
    ...
    url(r'^', include(genomix_users_urls, namespace='users')),
    ...
]

Make sure settings.py file has TEMPLATES and STATIC_URL set (example below):

TEMPLATES = [
    {
        # See: https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-TEMPLATES-BACKEND
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-dirs
        'DIRS': [
            os.path.join(ROOT_DIR, 'templates'),
            os.path.join(APPS_DIR, 'templates'),
        ],
        'OPTIONS': {
            # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-debug
            'debug': DEBUG,
            # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-loaders
            # https://docs.djangoproject.com/en/dev/ref/templates/api/#loader-types
            'loaders': [
                'django.template.loaders.filesystem.Loader',
                'django.template.loaders.app_directories.Loader',
            ],
            # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-context-processors
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.template.context_processors.i18n',
                'django.template.context_processors.media',
                'django.template.context_processors.static',
                'django.template.context_processors.tz',
                'django.contrib.messages.context_processors.messages',
                # Your stuff: custom template context processors go here
            ],
        },
    },
]

STATIC_URL = '/static/'

Make sure settings.py file has MIDDLEWARE set (example below):

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

Optional settings

Turn off the creation of associated user profiles in settings.py.

CREATE_PROFILE_ON_SAVE = False

Enable authentication to use JSON Web Token in settings.py:

REST_USE_JWT = True

REST_FRAMEWORK = {
    'DEFAULT_PERMISSION_CLASSES': (
        'rest_framework.permissions.IsAuthenticated',
    ),
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
        'rest_framework.authentication.SessionAuthentication',
        'rest_framework.authentication.BasicAuthentication',
    ),
}

Enable LDAP authentication in settings.py:

LDAP_AUTH_URL = 'ldap://chop.edu:3268'

LDAP_AUTH_USE_TLS = False

LDAP_AUTH_SEARCH_BASE = 'dc=chop,dc=edu'

LDAP_AUTH_OBJECT_CLASS = 'person'

LDAP_AUTH_USER_LOOKUP_FIELDS = ('username',)

LDAP_AUTH_USER_FIELDS = {
    "username": "sAMAccountName",
    "first_name": "givenName",
    "last_name": "sn",
    "email": "mail",
}

LDAP_AUTH_FORMAT_USERNAME = 'django_python3_ldap.utils.format_username_active_directory'

LDAP_AUTH_ACTIVE_DIRECTORY_DOMAIN = 'chop-edu'

AUTHENTICATION_BACKENDS = [
    'django.contrib.auth.backends.ModelBackend',
    'django_python3_ldap.auth.LDAPBackend',
]

Enable LDAP User group filtering in settings.py:

LDAP_AUTH_FORMAT_SEARCH_FILTERS = 'genomix_users.authentication.genomix_search_filters'

LDAP_AUTH_SEARCH_FILTER = 'CN=dgd_nexus_users,ou=DGD Groups,ou=SecurityGroups,ou=Research,ou=Managed By Others,dc=chop,dc=edu'

Sync User Profile with LDAP fields in settings.py:

LDAP_AUTH_SYNC_USER_RELATIONS = "genomix_users.authentication.sync_genomix_profile"

# User model fields mapped to the LDAP attributes that represent them.
LDAP_AUTH_PROFILE_FIELDS = {
    "title": "title",
}

Features

Running Tests

Does the code actually work?

source <YOURVIRTUALENV>/bin/activate
(myenv) $ pip install tox
(myenv) $ tox

Credits

Tools used in rendering this package:

History

0.1.0 (2017-12-03)

  • First release on PyPI.

  • Initial models and REST API.

0.2.0 (2017-12-11)

0.2.0 Changelog

  • Added Profile.

  • Added ability to sync profile from LDAP.

0.3.0 (2017-01-05)

0.3.0 Changelog

  • Added REST API filters.

0.3.1 (2017-01-12)

0.3.1 Changelog

  • Fixed route names for SimpleRouter

0.4.0 (2017-02-09)

0.4.0 Changelog

  • Updated requirements to latest

0.5.0 (2017-04-07)

0.5.0 Changelog

  • Added support for Django 2.0 and Python 3.6

  • Dropped support for Django < 1.11 and Python 2.7, 3.3, 3.4

0.5.1 (2017-04-10)

0.5.1 Changelog

  • Fixed issue with Admin registration. From now on - users can import and use this in their apps

0.5.2 (2017-04-18)

0.5.2 Changelog

  • Updated 3rd party libs

0.5.3 (2018-05-16)

0.5.3 Changelog

  • Updated setup.py to read install_requires from requirements.txt

0.5.4 (2018-08-13)

0.5.4 Changelog

  • Updated 3rd party requirements. Some requirements had changed so it was causing failures

0.5.5 (2018-10-29)

0.5.5 Changelog

  • Updated 3rd party requirements.

0.5.6 (2019-02-08)

0.5.6 Changelog

  • Updated 3rd party requirements.

0.5.7 (2019-04-10)

0.5.7 Changelog

  • Updated 3rd party requirements.

0.5.8 (2019-05-31)

0.5.8 Changelog

  • Updated to latest cookiecutter template

0.5.9 (2019-07-26)

0.5.9 Changelog

  • Updated 3rd party requirements.

0.5.10 (2019-08-09)

0.5.10 Changelog

  • Updated 3rd party requirements.

0.5.11 (2019-09-09)

0.5.11 Changelog

  • Updated 3rd party requirements.

Release files for django-genomix-users 0.5.11

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-genomix-users 0.5.11
File Size Uploaded
django-genomix-users-0.5.11.tar.gz 14.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-genomix-users 0.5.11
File Interpreter ABI Platform
django_genomix_users-0.5.11-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 27.3 kB

Release files / django-genomix-users-0.5.11.tar.gz

Download URL django-genomix-users-0.5.11.tar.gz
Size 14.7 kB
Tags Source
SHA-256 checksum
How to use checksums
cbacadf92b367c730b9d1d3cce8a46448707121d35ea33a18012ef9dca047312
BLAKE2b-256 checksum
How to use checksums
6a169b070407d0ec10c986817a835d32876e0cf1f8e35cd030083bdefb43b005
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.14.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.6.9

Release files / django_genomix_users-0.5.11-py2.py3-none-any.whl

Download URL django_genomix_users-0.5.11-py2.py3-none-any.whl
Size 12.6 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
7c662f9e8dd97a2d142b913602f31245f7efe41c3f6069e4dfad3f9c9412ef83
BLAKE2b-256 checksum
How to use checksums
ddad8182611ce9b5d354f093caca252c2213fb3aa996f55bb46b350162cfec37
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.14.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.6.9

Release history Release notifications | RSS feed

This release

0.5.11 This release

2 release files

0.5.9

2 release files

0.5.8

2 release files

0.5.7

2 release files

0.5.6

2 release files

0.5.5

2 release files

0.5.4

2 release files

0.5.3

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page