Skip to main content
travis-cli tests status for django-cuser PyPI Wheel PyPI Status PyPI License PyPI Format PyPI Py_versions PyPI Downloads PyPI Implementation PyPI Version PyPI Egg

Overview

cuser will bring you Current user of your django application from anywhere in your code. I know, sounds fantastic ;)

Supported Python versions

django-cuser currently can be run on multiple python versions:

  • Python 2 (2.7)

  • Python 3 (3.4, 3.5)

  • PyPy

Installing

django-cuser is also available at http://pypi.python.org/pypi/django-cuser So it can be install it by pip or easy_install:

$ pip install django-cuser

Or you can grab the latest version tarball:

$ python setup.py install

To enable django-cuser in your project

  • Add cuser to INSTALLED_APPS in your settings.py

  • Add cuser.middleware.CuserMiddleware to MIDDLEWARE_CLASSES after the authentication and session middleware.

Who is the current user

To set/get the user info, there is the following API:

from cuser.middleware import CuserMiddleware

Set the current user for this thread. Accepts user objects and login names:

CuserMiddleware.set_user(some_user)

Get the current user or None:

user = CuserMiddleware.get_user()

This will return some_user if there is no current user:

user = CuserMiddleware.get_user(some_user)

Forget the current user. It is always safe to call this, even if there is no current user:

CuserMiddleware.del_user()

The middleware automatically sets/deletes the current user for HTTP requests. For other uses (management commands, scripts), you will need to do this yourself.

CurrentUserField

cuser also provides a CurrentUserField, which can be used for auditing purposes. Use it as follows:

from cuser.fields import CurrentUserField

class MyModel(models.Model):
    ....
    creator = CurrentUserField(add_only=True, related_name="created_mymodels")
    last_editor = CurrentUserField(related_name="last_edited_mymodels")
    ...

This field is a ForeignKey to the settings.AUTH_USER_MODEL model and you can treat it as such.

Tests

django-cuser has been tested Django 1.8 and later. To run the the tests:

$ python manage.py test -v 2

It’s also available on travis-ci:

https://travis-ci.org/Alir3z4/django-cuser/

Metadata

Release files for django-cuser 2017.3.16

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-cuser 2017.3.16
File Size Uploaded Provenance
django-cuser-2017.3.16.tar.gz 8.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for django-cuser 2017.3.16
File Interpreter ABI Platform
django_cuser-2017.3.16-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 20.7 kB

Release files / django-cuser-2017.3.16.tar.gz

Download URL django-cuser-2017.3.16.tar.gz
Size 8.3 kB
Tags Source
SHA-256 checksum
How to use checksums
0d71bc8c4e48a452c7d3f86587b2f098ea30ff644d03bf193eba88302dd47060
BLAKE2b-256 checksum
How to use checksums
1ca5d94654ce4c9cb4bc6fcae7746acfac44eb6fcceefd3754f49c716c692e95
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / django_cuser-2017.3.16-py2.py3-none-any.whl

Download URL django_cuser-2017.3.16-py2.py3-none-any.whl
Size 12.5 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
bf5c3b4f7f4c9fd583f81c3ef16e5ba9e819c70aa1f6a5e8452c784c0a7297ec
BLAKE2b-256 checksum
How to use checksums
7d7e3005eb0a0b1f189ff9b6a8d23529bf46c7b8dfb1d4324275990792da3a29
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for django-cuser 2017.3.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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