API

Action Manager

class actstream.managers.ActionManager(*args, **kwargs)[source]

Default manager for Actions, accessed through Action.objects

action_object(obj, **kwargs)[source]

Stream of most recent actions where obj is the action_object. Keyword arguments will be passed to Action.objects.filter

actor(obj, **kwargs)[source]

Stream of most recent actions where obj is the actor. Keyword arguments will be passed to Action.objects.filter

any(obj, **kwargs)[source]

Stream of most recent actions where obj is the actor OR target OR action_object.

model_actions(model, **kwargs)[source]

Stream of most recent actions by any particular model

public(*args, **kwargs)[source]

Only return public actions

target(obj, **kwargs)[source]

Stream of most recent actions where obj is the target. Keyword arguments will be passed to Action.objects.filter

user(obj, with_user_activity=False, follow_flag=None, **kwargs)[source]

Create a stream of the most recent actions by objects that the user is following.

Follow Manager

class actstream.managers.FollowManager(*args, **kwargs)[source]

Manager for Follow model.

followers(actor, flag='')[source]

Returns a list of User objects who are following the given actor (eg my followers).

following(user, *models, **kwargs)[source]

Returns a list of actors that the given user is following (eg who im following). Items in the list can be of any model unless a list of restricted models are passed. Eg following(user, User) will only return users following the given user

for_object(instance, flag='')[source]

Filter to a specific instance.

is_following(user, instance, flag='')[source]

Check if a user is following an instance.

Views

actstream.views.actor(request, content_type_id, object_id)[source]

Actor focused activity stream for actor defined by content_type_id, object_id.

actstream.views.detail(request, action_id)[source]

Action detail view (pretty boring, mainly used for get_absolute_url)

actstream.views.follow_unfollow(request, content_type_id, object_id, flag=None, do_follow=True, actor_only=True)[source]

Creates or deletes the follow relationship between request.user and the actor defined by content_type_id, object_id.

actstream.views.followers(request, content_type_id, object_id, flag=None)[source]

Creates a listing of User``s that follow the actor defined by ``content_type_id, object_id.

actstream.views.following(request, user_id, flag=None)[source]

Returns a list of actors that the user identified by user_id is following (eg who im following).

actstream.views.model(request, content_type_id)[source]

Actor focused activity stream for actor defined by content_type_id, object_id.

actstream.views.respond(request, code)[source]

Responds to the request with the given response code. If next is in the form, it will redirect instead.

actstream.views.stream(request)[source]

Index page for authenticated user’s activity stream. (Eg: Your feed at github.com)

actstream.views.user(request, username)[source]

User focused activity stream. (Eg: Profile page twitter.com/justquick)

Feeds

class actstream.feeds.AbstractActivityStream[source]

Abstract base class for all stream rendering. Supports hooks for fetching streams and formatting actions.

format(action)[source]

Returns a formatted dictionary for the given action.

format_action_object(action)[source]

Returns a formatted dictionary for the action object of the action.

format_actor(action)[source]

Returns a formatted dictionary for the actor of the action.

format_item(action, item_type='actor')[source]

Returns a formatted dictionary for an individual item based on the action and item_type.

format_target(action)[source]

Returns a formatted dictionary for the target of the action.

get_object(*args, **kwargs)[source]

Returns the object (eg user or actor) that the stream is for.

get_stream(*args, **kwargs)[source]

Returns a stream method to use.

get_uri(action, obj=None, date=None)[source]

Returns an RFC3987 IRI ID for the given object, action and date.

get_url(action, obj=None, domain=True)[source]

Returns an RFC3987 IRI for a HTML representation of the given object, action. If domain is true, the current site’s domain will be added.

items(*args, **kwargs)[source]

Returns a queryset of Actions to use based on the stream method and object.

Atom

Compatible with Atom Activity Streams 1.0 spec

class actstream.feeds.AtomUserActivityFeed[source]

Atom feed of Activity for a given user (where actions are those that the given user follows).

class actstream.feeds.AtomModelActivityFeed[source]

Atom feed of Activity for a given model (where actions involve the given model as any of the entities).

class actstream.feeds.AtomObjectActivityFeed[source]

Atom feed of Activity for a given object (where actions involve the given object as any of the entities).

JSON

Compatible with JSON Activity Streams 1.0 spec

class actstream.feeds.AtomUserActivityFeed[source]

Atom feed of Activity for a given user (where actions are those that the given user follows).

class actstream.feeds.AtomModelActivityFeed[source]

Atom feed of Activity for a given model (where actions involve the given model as any of the entities).

class actstream.feeds.AtomObjectActivityFeed[source]

Atom feed of Activity for a given object (where actions involve the given object as any of the entities).

Actions

actstream.actions.action_handler(verb, **kwargs)[source]

Handler function to create Action instance upon action signal call.

actstream.actions.follow(user, obj, send_action=True, actor_only=True, flag='', **kwargs)[source]

Creates a relationship allowing the object’s activities to appear in the user’s stream.

Returns the created Follow instance.

If send_action is True (the default) then a <user> started following <object> action signal is sent. Extra keyword arguments are passed to the action.send call.

If actor_only is True (the default) then only actions where the object is the actor will appear in the user’s activity stream. Set to False to also include actions where this object is the action_object or the target.

If flag not an empty string then the relationship would marked by this flag.

Example:

follow(request.user, group, actor_only=False)
follow(request.user, group, actor_only=False, flag='liking')
actstream.actions.is_following(user, obj, flag='')[source]

Checks if a “follow” relationship exists.

Returns True if exists, False otherwise.

Pass a string value to flag to determine which type of “follow” relationship you want to check.

Example:

is_following(request.user, group)
is_following(request.user, group, flag='liking')
actstream.actions.unfollow(user, obj, send_action=False, flag='')[source]

Removes a “follow” relationship.

Set send_action to True (False is default) to also send a ``<user> stopped following <object> action signal.

Pass a string value to flag to determine which type of “follow” relationship you want to remove.

Example:

unfollow(request.user, other_user)
unfollow(request.user, other_user, flag='watching')

Decorators

actstream.decorators.stream(func)[source]

Stream decorator to be applied to methods of an ActionManager subclass

Syntax:

from actstream.decorators import stream
from actstream.managers import ActionManager

class MyManager(ActionManager):
    @stream
    def foobar(self, ...):
        ...

Templatetags

Start off your templates by adding:

{% load activity_tags %}
actstream.templatetags.activity_tags.activity_stream(context, stream_type, *args, **kwargs)[source]

Renders an activity stream as a list into the template’s context. Streams loaded by stream_type can be the default ones (eg user, actor, etc.) or a user defined stream. Extra args/kwargs are passed into the stream call.

{% activity_stream 'actor' user %}
{% for action in stream %}
    {% display_action action %}
{% endfor %}
actstream.templatetags.activity_tags.actor_url(parser, token)[source]

Renders the URL for a particular actor instance

<a href="{% actor_url request.user %}">View your actions</a>
<a href="{% actor_url another_user %}">{{ another_user }}'s actions</a>
actstream.templatetags.activity_tags.display_action(parser, token)[source]

Renders the template for the action description

{% display_action action %}
actstream.templatetags.activity_tags.follow_all_url(parser, token)[source]

Renders the URL to follow an object as both actor and target

<a href="{% follow_all_url other_user %}">
    {% if request.user|is_following:other_user %}
        stop following
    {% else %}
        follow
    {% endif %}
</a>

<a href="{% follow_all_url other_user 'watching' %}">
    {% is_following user group "watching" as is_watching %}
    {% if is_watching %}
        stop watching
    {% else %}
        watch
    {% endif %}
</a>
actstream.templatetags.activity_tags.follow_url(parser, token)[source]

Renders the URL of the follow view for a particular actor instance

<a href="{% follow_url other_user %}">
    {% if request.user|is_following:other_user %}
        stop following
    {% else %}
        follow
    {% endif %}
</a>

<a href="{% follow_url other_user 'watching' %}">
    {% is_following user group "watching" as is_watching %}
    {% if is_watching %}
        stop watching
    {% else %}
        watch
    {% endif %}
</a>
actstream.templatetags.activity_tags.is_following(user, actor)[source]

Returns true if the given user is following the actor

{% if request.user|is_following:another_user %}
    You are already following {{ another_user }}
{% endif %}