Skip to main content

Conveniently store reference to request user on thread/db level.

Project description

https://travis-ci.org/PaesslerAG/django-currentuser.svg?branch=master

Quickstart

Install django-currentuser:

pip install django-currentuser

Add it to the middleware classes in your settings.py:

MIDDLEWARE = (
    ...,
    'django_currentuser.middleware.ThreadLocalUserMiddleware',
)

Then use it in a project:

from django_currentuser.middleware import (
    get_current_user, get_current_authenticated_user)

# As model field:
from django_currentuser.db.models import CurrentUserField
class Foo(models.Model):
    created_by = CurrentUserField()

Differences to django-cuser

Both libraries serve the same purpose, but be aware of these differences (as of django-cuser v.2017.3.16):

  • django-currentuser’s CurrentUserField stores the reference to the request user at initialization of the model instance and still allows you to overwrite the value before saving. django-cuser sets the value in the pre_save handler of the field just before writing it to the database. Intermediate changes will be ignored.

  • django-cuser deletes the user reference from the thread after finishing a response and it will therefore no longer be available for testing purposes.

Release Notes

  • 0.4.0 - update supported versions - drop support for Python 3.4 - drop support for Django 2.0 - add support for Python 3.7 - add support for Django 2.2 - update tox3travis.py to not loose deployment feature

  • 0.3.4 - Use public Travis for packaging to remove dependency on outdated build system

  • 0.3.3 - drop Python 3.7 support due to build process problems

  • 0.3.1 - attempt to add Python 3.7 support

  • 0.3.0 - update supported versions according to https://www.djangoproject.com/download/#supported-versions and https://devguide.python.org/#status-of-python-branches - drop support for Python 3.2

  • 0.2.3 - support custom user model, drop Django 1.10 support

  • 0.2.2 - support Django 2.0

  • 0.2.1 - version fixes #9 - support Django 1.11.x and not just 1.11.0

  • 0.2.0 - New middleclass format - Adapt to new object based middle class format of Django 1.10+ - Drop support for deprecated Django versions 1.8 and 1.9

  • 0.1.1 - minor release - suppress warning for passed kwargs as long as they match the defaults (avoids them being printed during running tests when fields are cloned)

  • 0.1.0 - initial release - provides middleware + methods to set + retrieve reference of currently logged in user from thread - provides CurrentUserField that by default stores the currently logged in user - supports Django 1.10, 1.11 on python 2.7, 3.4, 3.5, and 3.6 - as per the official django docs

Contributing

As an open source project, we welcome contributions.

The code lives on github.

Reporting issues/improvements

Please open an issue on github or provide a pull request whether for code or for the documentation.

For non-trivial changes, we kindly ask you to open an issue, as it might be rejected. However, if the diff of a pull request better illustrates the point, feel free to make it a pull request anyway.

Pull Requests

  • for code changes

    • it must have tests covering the change. You might be asked to cover missing scenarios

    • the latest flake8 will be run and shouldn’t produce any warning

    • if the change is significant enough, documentation has to be provided

To trigger the packaging, run make release on the master branch with a changed version number.

Setting up all Python versions

sudo apt-get -y install software-properties-common
sudo add-apt-repository ppa:fkrull/deadsnakes
sudo apt-get update
for version in 3.5 3.6 3.7; do
  py=python$version
  sudo apt-get -y install ${py} ${py}-dev
done

Code of Conduct

As it is a Django extension, it follows Django’s own Code of Conduct. As there is no mailing list yet, please just email one of the main authors (see setup.py file or github contributors)

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-currentuser-0.4.0.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_currentuser-0.4.0-py2.py3-none-any.whl (6.4 kB view details)

Uploaded Python 2Python 3

File details

Details for the file django-currentuser-0.4.0.tar.gz.

File metadata

  • Download URL: django-currentuser-0.4.0.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/2.7.15

File hashes

Hashes for django-currentuser-0.4.0.tar.gz
Algorithm Hash digest
SHA256 478b3c09c40945b30f4d73d4f26d34574e0a62bb7816f96254105074e3532600
MD5 3d3072ab185ca6267215d1ecced6dd44
BLAKE2b-256 a2699547c46c3fcfd566b1088dc598e6202b09f22b994cf4b18a3ee89f638dab

See more details on using hashes here.

File details

Details for the file django_currentuser-0.4.0-py2.py3-none-any.whl.

File metadata

  • Download URL: django_currentuser-0.4.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/2.7.15

File hashes

Hashes for django_currentuser-0.4.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 5751ddd83948e5b21664333f3cb307d85766e4ac8314af8f85f7025a62e89c9b
MD5 312c0c376c6b5d892579af39fb790db6
BLAKE2b-256 d056de0e5e25100c74c7cc7d42580a0daad24c2844c895f5beb303771b6608b5

See more details on using hashes here.

Supported by

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