Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Extend Django sessions with a foreign key back to the user, allowing enumerating all user's sessions.

License

NotificationsYou must be signed in to change notification settings

jazzband/django-user-sessions

Repository files navigation

JazzbandGitHub ActionsTest CoveragePyPI

Django includes excellent built-in sessions, however all the data is hiddenaway into base64 encoded data. This makes it very difficult to run a query onall active sessions for a particular user. django-user-sessions fixes thisand makes session objects a first class citizen like other ORM objects. It isa drop-in replacement for django.contrib.sessions.

I would love to hear your feedback on this package. If you run intoproblems, please file an issue on GitHub, or contribute to the project byforking the repository and sending some pull requests. The package istranslated into English, Dutch and other languages. Please contribute your ownlanguage usingTransifex.

Also have a look at the bundled example templates and views to see how youcan integrate the application into your project.

Compatible with Django 3.2 and 4.2 on Python 3.8 to 3.11.Documentation is available atreadthedocs.org.

Features

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. Thisallows to show a list of active sessions to the user in the admin:

https://i.imgur.com/YV9Nx3f.png

And also in a custom layout:

https://i.imgur.com/d7kZtr9.png

Installation

Refer to theinstallation instructions in the documentation.

GeoIP

You need to setup GeoIP for the location detection to work. See the Djangodocumentation oninstalling GeoIP.

Getting help

For general questions regarding this package, please hop over to StackOverflow. If you think there is an issue with this package; check if theissue is already listed (either open or closed), and file an issue ifit's not.

Development

How to contribute

  • Fork the repository on GitHub and start hacking.
  • Run the tests.
  • Send a pull request with your changes.
  • Provide a translation usingTransifex.

Running tests

This project aims for full code-coverage, this means that your code should bewell-tested. Also test branches for hardened code. You can run the full testsuite with:

make test

Or run a specific test with:

make test TARGET=tests.tests.MiddlewareTest

For Python compatibility,tox is used. You can run the full test suite with:

tox

Releasing

The following actions are required to push a new version:

  • Update release notes

  • If any new translations strings were added, push the new source language toTransifex. Make sure translators have sufficient time to translate thosenew strings:

    make tx-push
  • Add migrations:

    python example/manage.py makemigrations user_sessionsgit commit user_sessions/migrations -m "Added migrations"
  • Update translations:

    make tx-pull
  • Package and upload:

    bumpversion [major|minor|patch]git push && git push --tagspython -m build --wheeltwine upload dist/*

License

This project is licensed under the MIT license.

Credits

This library was written byBouke Haarsma andcontributors.


[8]ページ先頭

©2009-2025 Movatter.jp