Middleware to make user information always available and to automatically log changes
Project description
Django-echelon - BIg Brother for your Django projects
Copyright (c) 2009-2011 Dennis Kaarsemaker <dennis@kaarsemaker.net>
2011 Atamert Ölçgun <muhuk@muhuk.com>
Overview
--------
Echelon does what its name implies: it keeps an eye on users. It allows you to
find out the current user from anywehere in your code and it tracks every
action users do.
Installing
----------
Install: python setup.py install
- Add 'echelon' to INSTALLED_APPS in your settings.py
- Add 'echelon.middleware.EchelonMiddleware' 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 echelon.middleware import EchelonMiddleware
# Set the current user for this thread. Accepts user objects and loginnames.
EchelonMiddleware.set_user(some_user)
# Get the current user or None
user = EchelonMiddleware.get_user()
# This will return some_user if there is no current user
user = EchelonMiddleware.get_user(some_user)
# Forget the current user. It is always safe to call this, even if there is no
# current user.
EchelonMiddleware.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.
echelon also provides a CurrentUserField, which can be used for auditing
purposes. Use it as follows:
from echelon.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 django.contrib.auth.models.User model and you
can treat it as such.
Automatic change logging
------------------------
Echelon will also automatically log all changes to almost all objects. Only
sessions and contenttypes are not logged. If you want to exclude other objects,
you can set this in settings.py. For example, if you don't want changes to
Permission objects logged you can add this:
ECHELON_LOGGING_BLACKLIST = (
('auth', 'Permission'),
)
You can also set an attribute in your model class to prevent logging:
class MyModel(models.Model):
...
echelon_log_changes = False
The first method is prefered for models you don't control, the second is better
for your own models.
To be able to review the changelog, add this pattern to the patterns in your
urls.py:
('^changelog/', include('echelon.urls'))
Copyright (c) 2009-2011 Dennis Kaarsemaker <dennis@kaarsemaker.net>
2011 Atamert Ölçgun <muhuk@muhuk.com>
Overview
--------
Echelon does what its name implies: it keeps an eye on users. It allows you to
find out the current user from anywehere in your code and it tracks every
action users do.
Installing
----------
Install: python setup.py install
- Add 'echelon' to INSTALLED_APPS in your settings.py
- Add 'echelon.middleware.EchelonMiddleware' 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 echelon.middleware import EchelonMiddleware
# Set the current user for this thread. Accepts user objects and loginnames.
EchelonMiddleware.set_user(some_user)
# Get the current user or None
user = EchelonMiddleware.get_user()
# This will return some_user if there is no current user
user = EchelonMiddleware.get_user(some_user)
# Forget the current user. It is always safe to call this, even if there is no
# current user.
EchelonMiddleware.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.
echelon also provides a CurrentUserField, which can be used for auditing
purposes. Use it as follows:
from echelon.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 django.contrib.auth.models.User model and you
can treat it as such.
Automatic change logging
------------------------
Echelon will also automatically log all changes to almost all objects. Only
sessions and contenttypes are not logged. If you want to exclude other objects,
you can set this in settings.py. For example, if you don't want changes to
Permission objects logged you can add this:
ECHELON_LOGGING_BLACKLIST = (
('auth', 'Permission'),
)
You can also set an attribute in your model class to prevent logging:
class MyModel(models.Model):
...
echelon_log_changes = False
The first method is prefered for models you don't control, the second is better
for your own models.
To be able to review the changelog, add this pattern to the patterns in your
urls.py:
('^changelog/', include('echelon.urls'))
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
django-echelon-1.2.tar.gz
(7.9 kB
view details)
File details
Details for the file django-echelon-1.2.tar.gz
.
File metadata
- Download URL: django-echelon-1.2.tar.gz
- Upload date:
- Size: 7.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b342802932d716b124b991e03ace21351c28e02fe53710c29b434b2e6ffaa62e |
|
MD5 | 983d1c70cb331dc30c4129eb59ee24ab |
|
BLAKE2b-256 | de3043a5628c75ae37709902e22b75e6c990ec395e1b191c148b4c3be79ff39b |