Simple, generic, activity streams from the actions on your site.
Supports Django versions 1.10.x, 1.11.x, 2.0 and above.
pip install django-simple-activity
INSTALLED_APPS = ( ... 'activity', )
django.contrib.authin your installed apps (why? read here).
Creating Activity Actions
from activity.logic import add_action, get_action_text user = User.objects.get(username='bob') # actor and verb example action = add_action(actor=user, verb='joined the website!') print(get_action_text(action)) -> 'bob joined the website!' # actor, verb and action another_user = User.objects.get(username='jessica') action = add_action( actor=user, verb='made friends with', action=another_user, timestamp=timezone.now() - timedelta(days=2) ) print(get_action_text(action)) -> 'bob made friends with jessica 2 days ago'
Further examples are in the tests.
Retrieving Activity Actions
Get all Activity Action records:
Get all public Activity Action records:
Get all private Activity Action records, where the actor is a given user
Action.objects.private(actor=user) # user being a Django User model instance
Here's an example use of
django-simple-activity which uses django signals
to trigger off the creation of an activity action when a new user registers on the site.
from django.db.models.signals import pre_save from django.dispatch import receiver from activity.logic import add_action from . models import UserProfile @receiver(pre_save, sender=UserProfile) def new_user_activity(sender, **kwargs): profile = kwargs.get('instance') # if no profile.id yet, then this is a new user registering if not profile.id: add_action(actor=profile.user, verb='joined the website!')
Running the unit tests
To test dependency installation and run the tests:
pip install tox tox