Skip to main content

Installable Django admin interface for bulk user creation from uploaded CSV file.

Project description

Installable Django admin interface for bulk user creation from uploaded CSV file.

Installation

First install using pip

pip install django-bulk-user-upload

Then add to your INSTALLED_PACKAGES

INSTALLED_PACKAGES = [
    . . .,
    'bulk_user_upload',
]

Then override the default User admin:

from django.contrib.admin import register
from django.contrib.auth import get_user_model

from bulk_user_upload.admin import BulkUploadUserAdmin

User = get_user_model()

@register(User)
class CustomUserAdmin(BulkUploadUserAdmin):
    pass

Setup and Customization

By default, the upload only processes username, email, permissions, and groups, e.g., you could use a CSV with the following information:

username email permissions groups
user user@example.com "auth.add_user,auth.change_user" "Example Users,Test Users"

But if you have a custom user model or need to capture more fields, you can modify the defaults by setting BULK_USER_UPLOAD in settings.py. Below are the defaults:

BULK_USER_UPLOAD = {
    'USERNAME_FIELD': 'username',  # user model username field
    'EMAIL_FIELD': 'email',  # user model email field
    'LOGIN_URL': '/',  # used in account creation notification email template
    'USER_UPLOAD_FORM': 'bulk_user_upload.forms.BulkUserUploadForm',  # django admin upload form
    'USERS_PREPROCESSOR': 'bulk_user_upload.utils.UsersPreProcessor',  # cleanup/pre-process the uploaded CSV
    'USERS_CREATOR': 'bulk_user_upload.utils.BaseUsersCreator',  # creates users from the uploaded CSV
    'USERS_VALIDATOR': 'bulk_user_upload.utils.UsersValidator',  # validates users from the uploaded CSV
    'USER_FIELD_VALIDATORS': {},  # add or override field-level validators
    'SEND_EMAILS_BY_DEFAULT': True,  # whether "send emails" is checked by default in the upload form
    'ACCOUNT_CREATION_EMAIL_SENDER_ADDRESS': None,  # email address used to notify user of account creation
    'ACCOUNT_CREATION_EMAIL_SUBJECT': 'Account Created',
    'EMAIL_SENDER': 'bulk_user_upload.utils.EmailSender',  # sends emails to created accounts
    # compute the name of the recipient, used in the account creation notification email template
    'GET_EMAIL_RECIPIENT_NAME': 'bulk_user_upload.utils.get_email_recipient_name',
}

For example, if you wanted to indicate whether your uploaded users are staff, you could modify these settings like so:

def intish(value):
    try:
        int(value)
        return True
    except:
        return False

BULK_USER_UPLOAD = dict(
    USER_FIELD_VALIDATORS=dict(
        is_staff=(
            lambda is_staff: not intish(is_staff) or int(is_staff) not in [True, False],
            lambda is_staff, *args: "is_staff must be 0 or 1.",
        )
    )
)

The sample project has an example of this and other customizations.

Demo

https://user-images.githubusercontent.com/12461302/133109664-3f2a223d-cc8c-4085-965a-c04e48065d72.mov

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-bulk-user-upload-0.1.0.tar.gz (20.0 kB view details)

Uploaded Source

Built Distribution

django_bulk_user_upload-0.1.0-py3-none-any.whl (27.2 kB view details)

Uploaded Python 3

File details

Details for the file django-bulk-user-upload-0.1.0.tar.gz.

File metadata

  • Download URL: django-bulk-user-upload-0.1.0.tar.gz
  • Upload date:
  • Size: 20.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.7

File hashes

Hashes for django-bulk-user-upload-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e2176b3fd71b394d155c75bfb37cd7a03403f9fe2bcf08905ce95c2f5045f1c4
MD5 7f0ec5aa315e9903a52b88dd8f3d53ff
BLAKE2b-256 2e31de9acccf318dbad972541d1a4bebeb60644f5d571941b4e76198aa46316e

See more details on using hashes here.

File details

Details for the file django_bulk_user_upload-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: django_bulk_user_upload-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 27.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.7

File hashes

Hashes for django_bulk_user_upload-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a4b5b11b02d2c2181a9c7ff665f4bc566a99fd8ff638d53bd84871ef58808c72
MD5 851f5134bed8bc2c163f7ce149a3ed07
BLAKE2b-256 84c4014d53d69fc81e15282f1fabc08ea968cd65052b833b0b8281c76dfe30cb

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page