Skip to main content

Django app for managing a timeline of events.

Project description

Django app for displaying a timeline of events.

Background

This is a very simple Django app that stores ‘events’ against a User object, providing a timeline of user events. It’s very open, the events don’t relate to anything concrete (this isn’t a model auditing app, although there is an optional GenericForeignKey on the Event model that you _can_ use if you wish) - it’s just a list of timestamped objects that can be used to track user interactions. Each event in the timeline has a category and a message field, along with a JSON field that can be used to store unstructured additional data. An event can optionally be related to another model via a generic foreign key.

The rendering of events is up to you - there is no default.

Installation

The project is available through PyPI as django-user-timeline:

$ pip install django-user-timeline

And the main package itself is just timeline:

>>> from timeline import models, views, urls, admin

Usage

Whenever something interesting happens, add an event. That’s it.

>>> from .models import Product, add_to_basket
>>> from timeline.models import TimelineEvent
>>> def add_product(request, product_id):
...     """View function to add product to user's basket."""
...     product = get_object_or_404(Product, id=id)
...     add_to_basket(request.user, product)
...     event = TimelineEvent.objects.create_event(
...         user=request.user,
...         category='add_to_basket',
...         message='You added %s to your basket' % product,
...         content_object=product,
...         context = {
...             "product_id": product_id,
...             "price_paid": 10.00,
...             "on_sale": False
...         }
...     )
...     return HttpResponse("...")

How you use the timeline is up to you - display it on the site, use it for reporting, etc. A user’s timeline is available directly via the related_name property of timeline:

>>> from django.contrib.auth.models import User
>>> from timeline.models import TimelineEvent
>>> user = User.objects.get(id=1)
>>> assert user.timeline.all() == TimelineEvent.objects.filter(user=user)

Tests

Tests are run using tox, and are run on commit pushes through Travis-CI.

Contributing

Standard GH rules apply: clone the repo to your own account, create a branch, make sure you update the tests, and submit a pull request.

Status

This is currently a placeholder for an application that is in development (hence 0.0.0).

Project details


Supported by

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