Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 26 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
##Stream Django
## Stream Django
[![Build Status](https://travis-ci.org/GetStream/stream-django.svg?branch=master)](https://travis-ci.org/GetStream/stream-django) [![Coverage Status](https://coveralls.io/repos/github/GetStream/stream-django/badge.svg?branch=master)](https://coveralls.io/github/GetStream/stream-django?branch=master) [![PyPI version](https://badge.fury.io/py/stream-django.svg)](http://badge.fury.io/py/stream-django)

This package helps you create activity streams & newsfeeds with Django and [GetStream.io](https://getstream.io).

###Build activity streams & news feeds
### Build activity streams & news feeds

<p align="center">
<img src="https://dvqg2dogggmn6.cloudfront.net/images/mood-home.png" alt="Examples of what you can build" title="What you can build"/>
Expand All @@ -25,7 +25,7 @@ You can check out our example apps built using this library (you can deploy them
* [Twitter for scientists example app](https://github.com/GetStream/django_twitter)


###Table of Contents
### Table of Contents
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->

Expand All @@ -44,7 +44,7 @@ You can check out our example apps built using this library (you can deploy them

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

###Update from <1.3
### Update from <1.3

Stream default names for feeds changed from flat and aggregated to timeline and timeline_aggregated. The default configuration of stream_django changed
to match the new names. If you did you not override the `STREAM_NEWS_FEEDS` settings and want to upgrade to 1.3 or later, make sure that you add this to your Django setting:
Expand All @@ -53,7 +53,7 @@ to match the new names. If you did you not override the `STREAM_NEWS_FEEDS` sett
STREAM_NEWS_FEEDS = {'flat':'flat', 'aggregated':'aggregated'}
```

###Installation
### Installation

Install stream_django package with pip:

Expand All @@ -75,7 +75,7 @@ STREAM_API_SECRET = 'my_api_secret_key'
Login with Github on getstream.io and add
```STREAM_API_KEY``` and ```STREAM_API_SECRET``` to your Django settings module (you can find them in the dashboard).

###Model integration
### Model integration

Stream Django can automatically publish new activities to your feed. Simple mixin the Activity class on the models you want to publish.

Expand All @@ -91,7 +91,7 @@ class Like(models.Model, Activity):

Every time a Tweet is created it will be added to the user's feed. Users which follow the given user will also automatically get the new tweet in their feeds.

####Activity fields
#### Activity fields

Models are stored in feeds as activities. An activity is composed of at least the following fields: **actor**, **verb**, **object**, **time**. You can also add more custom data if needed.
The Activity mixin will try to set things up automatically:
Expand All @@ -115,7 +115,7 @@ class Tweet(models.Model, Activity):

```

####Activity extra data
#### Activity extra data

Often you'll want to store more data than just the basic fields. You achieve this by implementing the extra_activity_data method in the model.

Expand All @@ -131,23 +131,23 @@ class Tweet(models.Model, Activity):
```


###Feed manager
### Feed manager

Django Stream comes with a feed_manager class that helps with all common feed operations.

####Feeds bundled with feed_manager
#### Feeds bundled with feed_manager

To get you started the manager has 4 feeds pre configured. You can add more feeds if your application needs it.
The three feeds are divided in three categories.

#####User feed:
##### User feed:
The user feed stores all activities for a user. Think of it as your personal Facebook page. You can easily get this feed from the manager.
```python
from stream_django.feed_manager import feed_manager

feed_manager.get_user_feed(user_id)
```
#####News feeds:
##### News feeds:
The news feeds (or timelines) store the activities from the people you follow.
There is both a simple timeline newsfeed (similar to twitter) and an aggregated version (like facebook).

Expand All @@ -156,7 +156,7 @@ timeline = feed_manager.get_news_feeds(user_id)['timeline']
timeline_aggregated = feed_manager.get_news_feeds(user_id)['timeline_aggregated']

```
#####Notification feed:
##### Notification feed:
The notification feed can be used to build notification functionality.

<p align="center">
Expand Down Expand Up @@ -192,27 +192,27 @@ class Follow(models.Model, Activity):
```


####Follow a feed
#### Follow a feed
The create the newsfeeds you need to notify the system about follow relationships. The manager comes with APIs to let a user's news feeds follow another user's feed. This code lets the current user's timeline and timeline_aggregated feeds follow the target_user's personal feed.

```
```python
feed_manager.follow_user(request.user.id, target_user)

```

### Showing the newsfeed

####Activity enrichment
#### Activity enrichment

When you read data from feeds, a like activity will look like this:

```
```python
{'actor': 'core.User:1', 'verb': 'like', 'object': 'core.Like:42'}
```

This is far from ready for usage in your template. We call the process of loading the references from the database enrichment. An example is shown below:

```
```python
from stream_django.enrich import Enrich

enricher = Enrich()
Expand All @@ -223,7 +223,7 @@ enriched_activities = enricher.enrich_activities(activities)



####Templating
#### Templating

Now that you've enriched the activities you can render the template.
For convenience we include the render activity template tag:
Expand Down Expand Up @@ -259,7 +259,7 @@ The example below will use the template activity/[aggregated]/homepage_%(verb)s.
```


###Settings
### Settings

**STREAM_API_KEY**
Your stream site api key. Default ```''```
Expand Down Expand Up @@ -288,17 +288,17 @@ The name of the feed (as it is configured in your GetStream.io Dasboard) where a
**STREAM_DISABLE_MODEL_TRACKING**
Disable automatic tracking of Activity models. Default ```False```

###Temporarily disabling the signals
### Temporarily disabling the signals

Model syncronization is disabled during schema/data migrations runs, syncdb and fixture loading (and during django test runs).
You can completely disable feed publishing via the ```STREAM_DISABLE_MODEL_TRACKING``` django setting.


###Customizing enrichment
### Customizing enrichment

Sometimes you'll want to customize how enrichment works. The documentation will show you several common options.

####Enrich extra fields
#### Enrich extra fields

If you store references to model instances in the activity extra_data you can use the Enrich class to take care of it for you

Expand All @@ -320,7 +320,7 @@ activities = feed.get(limit=25)['results']
enriched_activities = enricher.enrich_activities(activities)
```

####Change how models are retrieved
#### Change how models are retrieved

The enrich class that comes with the packages tries to minimise the amount of database queries. The models are grouped by their class and then retrieved with a pk__in query. You can implement a different approach to retrieve the instances of a model subclassing the ```stream_django.enrich.Enrich``` class.

Expand Down Expand Up @@ -350,7 +350,7 @@ class AnotherEnrich(Enrich):
```


####Preload related data
#### Preload related data

You will commonly access related objects such as activity['object'].user. To prevent your newsfeed to run N queries you can instruct the manager to load related objects. The manager will use Django's select_related functionality. (https://docs.djangoproject.com/en/dev/ref/models/querysets/#select-related).

Expand All @@ -363,7 +363,7 @@ class Tweet(models.Model, Activity):

```

###Low level APIs access
### Low level APIs access
When needed you can also use the low level Python API directly.
The full explanation can be found in the [getstream.io documentation](https://getstream.io/docs/).

Expand Down