Django User Status
A simple Django package to track and display a user's online/offline status and last seen time using Django's caching framework.
Installation
-
Install the package:
pip install django-user-status -
Add the middleware to your
settings.py:MIDDLEWARE = [ # ... other middleware 'django_user_status.middleware.UserStatusMiddleware', ]
redis example in settings.py (if you are using redis)
CACHES = {
"default": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": "redis://user:password@localhost:6379",
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
},
}
}
Load the template tags in your templates:
{% load user_status_tags %}
to use the template tags you need to add "django_user_status" to your INSTALLED_APPS
django_user_status
Configuration (Optional) You can customize the package's behavior by adding the following settings to your settings.py file.
- USER_STATUS_CACHE_DURATION: The time in seconds that a user is considered "online" after their last request. Defaults to 300 (5 minutes).
- USER_STATUS_CACHE_KEY_PREFIX: The prefix for the cache key. Useful to avoid key collisions. Defaults to 'last_seen'. Example settings.py:
Set the user to be "online" for 10 minutes
USER_STATUS_CACHE_DURATION = 600
Use a different cache key prefix
USER_STATUS_CACHE_KEY_PREFIX = 'user_activity'
Usage In your templates: To show a user's status:
{% get_user_status user %}
To show the last seen time:
{% get_last_seen user %}
What's New in Version 0.1.2
-
Bug Fix: Resolved a TypeError related to timezone-aware and naive datetimes. The package now correctly uses timezone-aware datetimes for all cache and status checks, ensuring reliability.
-
Added Unit Tests: Comprehensive unit tests have been added to ensure the reliability and correctness of the middleware and template tags.
Metadata
Release files for django-user-status 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| django_user_status-0.1.3.tar.gz | 4.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_user_status-0.1.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.4 kB
Release files / django_user_status-0.1.3.tar.gz
| Download URL | django_user_status-0.1.3.tar.gz |
|---|---|
| Size | 4.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b6bdf809aad3ef73033bcff3906784e9fb94e487518c66f53a89300dc032f633
|
|
BLAKE2b-256 checksum How to use checksums |
15067f311f587f1626bd372692f29fcc9faa7c427719d2475cbb1eadb24a2c86
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.0
|
Release files / django_user_status-0.1.3-py3-none-any.whl
| Download URL | django_user_status-0.1.3-py3-none-any.whl |
|---|---|
| Size | 6.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5fa150819d2ed9458105638072b4f9d90543e33e6d4ed534276b2b22edc94a38
|
|
BLAKE2b-256 checksum How to use checksums |
19fb59f8806fcb1272248ad4fb1e8412efddf5fc8b6fb3f7845e920667baa2c9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.0
|