Wiki

Clone wiki

django-online-status / Home

django-online-status

Online status for authenticated users [online, idle, offline] and a list of current users online. Both are asy to display using simple templatetags.

There are no database models, everything is stored in your cache backend.

Install

Grab the code

hg clone http://bitbucket.org/zalew/django-online-status

Install using setuptools

python setup.py install

or simply put the package directory /online_status/ anywhere accessible.

Add 'online_status' to your INSTALLED_APPS.

Add 'online_status.middleware.OnlineStatusMiddleware' to your MIDDLEWARE_CLASSES, below Session and Auth:

MIDDLEWARE_CLASSES = (
    # ...
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'online_status.middleware.OnlineStatusMiddleware',
)

Running tests

python manage.py test online_status

Urls are not needed for proper working, but it won't pass the tests without it

(r'^online/', include('online_status.urls')),  

note: response content is tested against desired output, so if you have some adjustments on displaying html, like stripping whitespace middleware or whatever, it may raise an error

Settings

You can change the seconds interval when user goes idle or offline

USERS_ONLINE__TIME_IDLE = 60*5 # 5 minutes
USERS_ONLINE__TIME_OFFLINE = 60*10 # 10 minutes

and also cache prefixes if needed

USERS_ONLINE__CACHE_PREFIX_USER = 'online_user'
USERS_ONLINE__CACHE_USERS = 'online_users'

Using the templatetags

There are 2 ready templatetags for easy usage.

{% load online_status_tags %}

status for user:
{% user_status user_object %}

users online:
{% online_users 30 %} 

user_object has to be a User instance, 30 is number of users displayed and it's not required.

Editing templates

You can override their templates, copy the /templates/online_status/ folder to your templates directory and edit to fit your needs.

Check example.html and go to {% url online_users_example %} to see it in action.

There's a templatefilter for the status value (check user_status.html), as it's saved 0 or 1 for idle and online. Please contribute translations for the text version.

Issues? Want to contribute?

Report any issues here. If you have any ideas, you can submit a proposal but better yet feel free to fork it, do it yourself and if it's ok I'll merge it.

There are just 3 messages in the locale files to translate, submit your language please.

Updated