Skip to main content

Tracks the time of users' last actions.

Project description

Tracks the time of each user’s last action

Using middleware, django-online-users will keep track of each user and the timestamp of their last action in the database.

Admins can see this data in the admin portal, and the database can be queried using timedeltas.

This is meant for smaller applications as each HTTP request will result in a database entry update.

Requirements

  • Python: 2.7, 3.3, 3.4, 3.5, 3.6

  • Django: 1.10+

Setup

  1. Add “online_users” to your INSTALLED_APPS

INSTALLED_APPS = [
    ...
    'online_users',
]
  1. Add the OnlineNowMiddleware to your MIDDLEWARE_CLASSES after the SessionMiddleware

MIDDLEWARE_CLASSES = (
    ...
    'online_users.middleware.OnlineNowMiddleware',
)
  1. Run python manage.py migrate to create the tables in the database.

Use

from datetime import timedelta
...
user_activity_objects = OnlineUserActivity.get_user_activities()
number_of_active_users = user_activity_objects.count()
  • A timedelta can also be specified to the get_user_activities() with to find activity

from datetime import timedelta
...
user_activity_objects = OnlineUserActivity.get_user_activities(timedelta(minutes=60)
users = (user for user in user_activity_objects)

API

OnlineUserActivity holds two values: user, the user in question, and last_activity, a timestamp stored as a DateTimeField.

OnlineUserActivity.get_user_activities() will return OnlineUserActivity objects for the last 15 minutes by default. Developers can also pass in a time delta of a different length of time for the query. The response is a QuerySet containing the active users during that time period, and the items are sorted in descending chronological order.

Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

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

Source Distribution

django-online-users-0.1.tar.gz (5.4 kB view details)

Uploaded Source

Built Distributions

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

django_online_users-0.3-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

django_online_users-0.3-py2-none-any.whl (9.2 kB view details)

Uploaded Python 2

django_online_users-0.1-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file django-online-users-0.1.tar.gz.

File metadata

File hashes

Hashes for django-online-users-0.1.tar.gz
Algorithm Hash digest
SHA256 6d9a82cd60d97eeb20ec2c12712c4ea16f0fcbe322217d5cab783c64c6ede147
MD5 e77d472b45e98535aad8b711bf5c7319
BLAKE2b-256 eae3017e5e08e0619127b1f49fc9993c253f0ef7d759996c67f0472036417fa4

See more details on using hashes here.

File details

Details for the file django_online_users-0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for django_online_users-0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d235040c1f2b76739b742c7a70c78f602c1faa6d084ea6b22782ef84b9289793
MD5 26f2e5aab349e0c42f45942a70eecdbb
BLAKE2b-256 8cf383ad96a0b6b840d282abe38dcd89e8338072ed1f3ebc7b28f304cc18baa5

See more details on using hashes here.

File details

Details for the file django_online_users-0.3-py2-none-any.whl.

File metadata

File hashes

Hashes for django_online_users-0.3-py2-none-any.whl
Algorithm Hash digest
SHA256 04906a4a580bb0574fb34d73afd6f2938816ff8fef62431399ee4561d37df76c
MD5 8cefb688f4805e91b1737d5df8502de8
BLAKE2b-256 4cca59f65d32be134b2eea6ea89cbdba605cbbd6be005a5bda53a83820f601a6

See more details on using hashes here.

File details

Details for the file django_online_users-0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for django_online_users-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 26f6ecadb16057a29898e1219b86bddaec027c9fe4c2abcc037267034ea7e5ee
MD5 43729f0c5a7d1b9a6db767240c83beef
BLAKE2b-256 fead9cf0c2fe3acb0d9d782b01bc136d28a117d606d0806d5b60caa2cff5c860

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