actable

Flexible activity stream supporting multiple associated objects and fast denormalized look-ups


Keywords
actable
License
Apache-2.0
Install
pip install actable==0.1.2

Documentation

actable

https://travis-ci.org/michaelpb/actable.svg?branch=master

Flexible activity stream for Python Django supporting an arbitrary number of associated objects and fast denormalized look-ups. Rendering can be fast too, with in-DB cached HTML and/or context.

The purpose of Actable is to make it easy and unobtrusive to add activity log-like streams to as many objects in your database as possible, and make fetching and rendering those simple and fast: a single query without joins, selecting and ordering only on indexed fields.

Features

Instead of limiting yourself to "Actor, Verb, Object", you can have any number of relations specified by a dictionary, as such:

class ProjectBlogPost:
    def get_actable_relations(self):
        # 'Alice created Blog Post Title about Project Name, on the topic
        # of Space'
        return {
            'subject': self.user,
            'verb': 'created',
            'object': self,
            'project': self.project,
            'topic': self.topic,
        }

The notable advantage of this is that the event would be accessible from the user page, the project page, the blog post page, and even the topic page (e.g., all related objects are linked). Since this would normally result in a complicated and arbitrary JOIN across many tables, the context (and, optionally, rendered HTML snippets) are cached for each content type, so only a much simpler query is required.

Quickstart

Install actable:

pip install actable

Add it to your INSTALLED_APPS, and specify which models to which you wish it to register save hooks:

INSTALLED_APPS = (
    ...
    'actable.apps.ActableConfig',
    ...
)

ACTABLE_MODELS = [
    'myapp.MyModel',
    'myapp.MyOtherModel',
]

Use

Running Tests

Does the code actually work?

source <YOURVIRTUALENV>/bin/activate
(myenv) $ pip install tox
(myenv) $ tox

Credits

Tools used in creating this package: