Welcome to django-simple-friends’s documentation!¶
Contents:
About django-simple-friends¶
I started developing django-simple-friends when I needed a simple app that handles friendships for my project. django-friends of Pinax was mature and well written but it was also handling contacts and invitations. So I decided to create my own app and steal some ideas from django-friends.
You can get community support at the mailing list.
Highlights¶
- Only the relationships between registered users are managed.
- Friending with double confirmation. When a user adds another user as a friend, only when the other user accepts or tries to add the first user as a friend, the friendship relationship is created.
- Blocking is possible.
Setting up django-simple-friends¶
Installation¶
Install django-simple-friends package:
pip install django-simple-friends
Add friends to your INSTALLED_APPS setting:
INSTALLED_APPS = ( # Other apps 'friends', )
Run syncdb to create tables and seed friendship data for existing users:
python manage.py syncdb
Run tests to make sure the app is installed correctly:
python manage.py test friends
Optionally include friends.urls to your URLconf:
urlpatterns = patterns('', # Other entries (r'^friends/', include('friends.urls')), )
Development Setup¶
If you want to develop django-simple-friends you can follow the steps below to set up a development environment.
Log-in to your GitHub account and fork the project.
Create a virtual environment:
virtualenv --no-site-packages django-simple-friends
Create a local repository:
cd django-simple-friends . bin/activate git clone git@github.com:muhuk/django-simple-friends.git src
Warning
You need to replace muhuk with your GitHub username in the command above.
Run the tests to make sure everyting is set up correctly:
cd src python example/manage.py test friends
Pick an issue to work on.
Changes¶
Version 1.0.0 - Mar 16, 2013¶
Some view classes are renamed:
BaseFriendshipActionView -> BaseActionView FriendshipBlockView -> UserBlockView FriendshipUnblockView -> UserUnblockView
If you are using only the view functions or the provided
urls.py
, then you don’t need to change your code.related_name
‘s for theForeignKey
‘s toUser
fromFriendshipRequest
are changed asfriendshiprequests_from
andfriendshiprequests_to
. Please replace any references toinvitations_from
andinvitations_to
in your code.
Version 0.5 - Oct 7, 2012¶
Tested with Django versions 1.3 & 1.4.
friend_list
view is removed. Seefriends
template filter.- View functions are rewritten as class based views. But they still work as aliases.
post_syncdb
signals to fix the issue ofUser
s withoutFriendship
s.- Proper Sphinx powered documentation.
- German & Spanish translations.
Version 0.4 - Feb 4, 2010¶
- Initial release.
Package Reference¶
How to display a list of friends for a user¶
Use friends()
template filter to
obtain a QuerySet
containing the
User
‘s who are friends with the filter’s
argument:
{% load friends %}
<h3>Friends</h3>
<ul>{% for friend in user|friends %}
<li>{{ friend.get_full_name }}</li>
{% endfor %}</ul>
The code above should produce a result like this:
<h3>Friends</h3>
<ul>
<li>Lenda Murray</li>
<li>Sharon Bruneau</li>
<li>Cory Everson</li>
</ul>
Package Reference¶
Views¶
Class Based Views¶
All the views are implemented as classes but view functions are also provided.
-
class
friends.views.
BaseActionView
(**kwargs)¶ Base class for action views.
-
set_url
(request, **kwargs)¶ Set the
url
attribute so that it can be used whenget_redirect_url()
is called.url
is determined using the following methods, in order:- It can be set in the urlconf using
redirect_to
keyword argument. - If
redirect_to_param
keyword argument is set in urlconf, the request parameter with that name will be used. In this case the request parameter must be provided in runtime. - If the request has
redirect_to
to parameter is present, its value will be used. - If
REDIRECT_FALLBACK_TO_PROFILE
setting isTrue
, current user’s profile URL will be used. HTTP_REFERER
header’s value will be used if exists.- If all else fail,
'/'
will be used.
- It can be set in the urlconf using
-
-
class
friends.views.
FriendshipAcceptView
(**kwargs)¶
-
class
friends.views.
UserBlockView
(**kwargs)¶
-
class
friends.views.
FriendshipCancelView
(**kwargs)¶
-
class
friends.views.
FriendshipDeclineView
(**kwargs)¶
-
class
friends.views.
FriendshipDeleteView
(**kwargs)¶
-
class
friends.views.
FriendshipRequestView
(**kwargs)¶
-
class
friends.views.
UserUnblockView
(**kwargs)¶
View Functions¶
Tip
If you want to customize the views provided, check out Class Based Views first.
-
friends.views.
friendship_request
(request, *args, **kwargs)¶
-
friends.views.
friendship_accept
(request, *args, **kwargs)¶
-
friends.views.
friendship_decline
(request, *args, **kwargs)¶
-
friends.views.
friendship_cancel
(request, *args, **kwargs)¶
-
friends.views.
friendship_delete
(request, *args, **kwargs)¶
-
friends.views.
user_block
(request, *args, **kwargs)¶
-
friends.views.
user_unblock
(request, *args, **kwargs)¶
Models¶
-
class
friends.models.
FriendshipRequest
(*args, **kwargs)¶ An intent to create a friendship between two users.
See also
There should never be complementary
FriendshipRequest
‘s, as inuser1
requests to be friends withuser2
whenuser2
has been requested to be friends withuser1
. See howFriendshipRequestView
checks the existence of aFriendshipRequest
fromto_user
tofrom_user
.-
accept
()¶ Create the
Friendship
betweenfrom_user
andto_user
and mark this instance as accepted.friendship_accepted
is signalled on success.See also
-
cancel
()¶ Deletes this
FriendshipRequest
friendship_cancelled
is signalled on success.See also
-
decline
()¶ Deletes this
FriendshipRequest
friendship_declined
is signalled on success.See also
-
-
class
friends.models.
FriendshipManager
¶ -
are_friends
(user1, user2)¶ Indicate if
user1
anduser2
are friends.Parameters: Return type: bool
-
befriend
(user1, user2)¶ Establish friendship between
user1
anduser2
.Important
Instead of calling this method directly,
FriendshipRequest.accept()
, which calls this method, should be used.Parameters:
-
-
class
friends.models.
Friendship
(*args, **kwargs)¶ Represents the network of friendships.
-
friend_count
()¶ Return the count of
friends
. This method is used inFriendshipAdmin
.Return type: int
-
Signals¶
friendship_accepted¶
-
friends.signals.
friendship_accepted
¶ Sent when a
FriendshipRequest
is accepted.Arguments sent with this signal:
sender
FriendshipRequest
instance that is accepted.
friendship_declined¶
-
friends.signals.
friendship_declined
¶ Sent when a
FriendshipRequest
is declined byto_user
.Arguments sent with this signal:
sender
FriendshipRequest
instance that is declined.
friendship_cancelled¶
-
friends.signals.
friendship_cancelled
¶ Sent when a
FriendshipRequest
is cancelled byfrom_user
.Arguments sent with this signal:
sender
FriendshipRequest
instance that is cancelled.
Signal Handlers¶
-
signals.
create_friendship_instance
(sender, instance, created, raw, **kwargs)¶ Create a
FriendshipRequest
for newly createdUser
.See also
post_save
built-in signal.
-
signals.
create_userblocks_instance
(sender, instance, created, raw, **kwargs)¶ Create a
UserBlocks
for newly createdUser
.See also
post_save
built-in signal.