Skip to main content

A Django package to show online/offline status and last seen time.

Project description

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

  1. Install the package: pip install django-user-status

  2. 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_user_status-0.1.3.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_user_status-0.1.3-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file django_user_status-0.1.3.tar.gz.

File metadata

  • Download URL: django_user_status-0.1.3.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.0

File hashes

Hashes for django_user_status-0.1.3.tar.gz
Algorithm Hash digest
SHA256 b6bdf809aad3ef73033bcff3906784e9fb94e487518c66f53a89300dc032f633
MD5 a20249437a8c4bf49b6576460425377d
BLAKE2b-256 15067f311f587f1626bd372692f29fcc9faa7c427719d2475cbb1eadb24a2c86

See more details on using hashes here.

File details

Details for the file django_user_status-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for django_user_status-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 5fa150819d2ed9458105638072b4f9d90543e33e6d4ed534276b2b22edc94a38
MD5 128fdab87a452d56020e82aa6fda96c0
BLAKE2b-256 19fb59f8806fcb1272248ad4fb1e8412efddf5fc8b6fb3f7845e920667baa2c9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page