Django Easy Friends is a friendship tool for Django framework. It has features like sending invitations, friendship creation, blocking users, importing contacts from external services and auto suggesting friends based on imported contacts. It consist of two applications: friends and friends.contrib.suggestions.
- Sending invitations
- Accepting and declining invitations
- Blocking users from sending invitations
- Listing friends
- Listing friends of friend (optional)
- Django
- django-notification (optional)
Add to your
INSTALLED_APPS
and run syncdb:INSTALLED_APPS = ( ..., 'friends', )
Add to your
urlpatterns
in projectsurls.py
file:urlpatterns = patterns('', ... url(r'^friends/', include('friends.urls')), )
Overwrite
friends/base.html
template and insert{% block friends_title %}{% endblock %}
into block where page title should be and{% block friends_content %}{% endblock %}
into block where page content should be.
Availale settings:
FRIENDS_USE_NOTIFICATION_APP
(default:True
)- By default
notification
app is used if it is enabled inINSTALLED_APPS
, if this setting is set toFalse
notification
app will not be used. SHOW_FRIENDS_OF_FRIEND
(default:False
)- Allow users to view list of friends of their friends.
NOTIFY_ABOUT_NEW_FRIENDS_OF_FRIEND
(default:False
)- If
notification
app is enabled andFRIENDS_USE_NOTIFICATION_APP
is set toTrue
and this setting is set toTrue
users will be notified when one of their friends have new friend. NOTIFY_ABOUT_FRIENDS_REMOVAL
(default:False
)- If
notification
app is enabled andFRIENDS_USE_NOTIFICATION_APP
is set toTrue
and this setting is set toTrue
users will be notified when one of their friends removes them from friends.
If you want to take some actions when invitation or friendship is created or deleted then check sample signals usage in file friends/models.py
.
This app is a fork of django-friends app.
- Importing contacts from:
- Yahoo
- Creating friendship suggestions based on imported contacts
- httplib2 (
pip install httplib2
) - python-oauth2 (
pip install -e git://github.com/simplegeo/python-oauth2.git#egg=python-oauth2
) - django-oauth-access (
pip install -e git://github.com/eldarion/django-oauth-access.git#egg=django-oauth-access
) - gdata (
pip install gdata
) - facebook-sdk (
pip install -e git://github.com/pythonforfacebook/facebook-sdk.git#egg=facebook-sdk
) - python-twitter (
pip install python-twitter
) - django-celery (
pip install django-celery
) (optional but highly recommended)
friends
app must be installed already (read above)Add to your
INSTALLED_APPS
and run syncdb:INSTALLED_APPS = ( ..., 'friends.contrib.suggestions', )
Add to your
urlpatterns
in projectsurls.py
file:urlpatterns = patterns('', ... url(r'^friends/suggestions/', include('friends.contrib.suggestions.urls')), )
Available settings:
FRIENDS_SUGGESTIONS_IMPORT_RUNNER
(default:friends.contrib.suggestions.backends.runners.SynchronousRunner
)- This is class that is used for importing contacts. Default is synchronous runner but you should really use Celery (and django-celery) so this setting should be set to
friends.contrib.suggestions.backends.runners.AsyncRunner
.
There is one setting that is needed for django-oauth-access
:
OAUTH_ACCESS_SETTINGS = { 'facebook': { 'keys': { 'KEY': 'YOURAPPKEY', 'SECRET': 'yourappsecretcode', }, 'endpoints': { #'authorize': 'https://graph.facebook.com/oauth/authorize', 'authorize': 'https://www.facebook.com/dialog/oauth/', # url above may be blocked in user browser by something like Ghostery so this one is safer 'access_token': 'https://graph.facebook.com/oauth/access_token', 'callback': 'friends.contrib.suggestions.views.import_facebook_contacts', }, }, 'twitter': { 'keys': { 'KEY': 'YOURAPPKEY', 'SECRET': 'yourappsecretcode', }, 'endpoints': { 'request_token': 'https://api.twitter.com/oauth/request_token', 'authorize': 'http://twitter.com/oauth/authorize', 'access_token': 'https://twitter.com/oauth/request_token', 'callback': 'friends.contrib.suggestions.views.import_twitter_contacts', }, }, 'yahoo': { 'keys': { 'KEY': 'YOURAPPKEY', 'SECRET': 'yourappsecretcode', }, 'endpoints': { 'request_token': 'https://api.login.yahoo.com/oauth/v2/get_request_token', 'authorize': 'https://api.login.yahoo.com/oauth/v2/request_auth', 'access_token': 'https://api.login.yahoo.com/oauth/v2/get_token', 'callback': 'friends.contrib.suggestions.views.import_yahoo_contacts', }, }, 'linkedin': { 'keys': { 'KEY': 'YOURAPPKEY', 'SECRET': 'yourappsecretcode', }, 'endpoints': { 'request_token': 'https://api.linkedin.com/uas/oauth/requestToken', 'authorize': 'https://api.linkedin.com/uas/oauth/authorize', 'access_token': 'https://api.linkedin.com/uas/oauth/accessToken', 'callback': 'friends.contrib.suggestions.views.import_linkedin_contacts', }, }, }
Remember to change YOURAPPKEY
and yourappsecretcode
for each service. You can get them by registering your applications on this sites:
- Facebook: https://developers.facebook.com/apps
- Twitter: https://dev.twitter.com/apps/new
- Yahoo: https://developer.apps.yahoo.com/projects
- LinkedIn: https://www.linkedin.com/secure/developer
By default friends suggestions are created after each contacts import but there are other situations when you could want to create friends suggestions. One example is when new user is registered on your site. This new user has no imported contacts yet but other users have some imported contacts and maybe new user matches some of the already imported contact. Here is how to create friends suggestions on user activation using some signals:
First create signal receiver:
def find_friends_suggestions(sender, user, **kwargs): from friends.contrib.suggestions.models import FriendshipSuggestion FriendshipSuggestion.objects.create_suggestions_for_user_using_imported_contacts(user)
If django-easy-userena (or django-userena) app is used for managing users registration use this code:
from userena.signals import activation_complete activation_complete.connect(find_friends_suggestions, dispatch_uid="find_friends_suggestions_on_activation_complete")
If django-registration app is used use this code:
from registration.signals import user_activated user_activated.connect(find_friends_suggestions, dispatch_uid="find_friends_suggestions_on_user_activated")
This app is based on django-contacts-import app with some code taken from some of its forks.