Django sessions with a foreign key to the user
Project description
Django includes excellent built-in sessions, however all the data is hidden away into base64 encoded data. This makes it very difficult to run a query on all active sessions for a particular user. django-user-sessions fixes this and makes session objects a first class citizen like other ORM objects.
To get the list of a user’s sessions:
user.session_set.filter(expire_date__gt=now())
Or logout the user everywhere:
user.session_set.all().delete()
The user’s IP address and user agent are also stored on the session. This allows to show a list of active sessions to the user in the admin:
And also in a custom layout:
Installation
pip install django-user-sessions
In INSTALLED_APPS replace 'django.contrib.sessions' with 'user_sessions'.
In MIDDLEWARE_CLASSES replace 'django.contrib.sessions.middleware.SessionMiddleware' with 'user_sessions.middleware.SessionMiddleware'.
Add SESSION_ENGINE = 'user_sessions.backends.db'.
Add url(r'', include('user_sessions.urls', 'user_sessions')), to your urls.py.
Run python manage.py syncdb (or migrate) and start hacking!
GeoIP
You need to setup GeoIP for the location detection to work. See the Django documentation on installing GeoIP.
Example application
Also, have a look at the example application. It includes template examples and shows how to use the session list and delete views.
Compatibility
Tested on Django 1.4, 1.5 and 1.6 with Python 2.7 and 3.3. However it should work fine with Python 2.6 and 3.2 as well.
Contributing
Fork the repository on GitHub and start hacking.
Run the tests.
Send a pull request with your changes.
Provide a translation using Transifex.
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
File details
Details for the file django-user-sessions-0.1.2.tar.gz
.
File metadata
- Download URL: django-user-sessions-0.1.2.tar.gz
- Upload date:
- Size: 11.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | feb6204b63963285d021a9eecc5ea024b9bce530c64f4626dcbe99689293f7a0 |
|
MD5 | a5056bfd07c8e49ae83778972a5db3ca |
|
BLAKE2b-256 | 97e87392713879ad168e5b14b4f3468f3348c92875653175e09af307afd95545 |