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 %}

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

  • 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.2.tar.gz (4.4 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.2-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_user_status-0.1.2.tar.gz
  • Upload date:
  • Size: 4.4 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.2.tar.gz
Algorithm Hash digest
SHA256 ab63057e576a0ade6410f38f862547ae28de2e207af69ca03a7b8cc2574e2c66
MD5 10b70f2e2ebc25d33bf4237de44ea5da
BLAKE2b-256 260af963aeb901a69df843632ee1764ed12cdb328db6c6e862b8bc57cdea7dd7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for django_user_status-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1df05dfe055d283659d16c2fffef6e90c85473c3f4da48483a0ecf9e6e5a8287
MD5 2afa9b788fcf5781d4756569fb1b53c4
BLAKE2b-256 4462a275c87558348fb7ab069cadc7d365388ee8147d3997fb12de98f4beb53d

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