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 when get_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 is True, 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.
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 in user1 requests to be friends with user2 when user2 has been requested to be friends with user1. See how FriendshipRequestView checks the existence of a FriendshipRequest from to_user to from_user.

accept()

Create the Friendship between from_user and to_user and mark this instance as accepted.

friendship_accepted is signalled on success.

cancel()

Deletes this FriendshipRequest

friendship_cancelled is signalled on success.

decline()

Deletes this FriendshipRequest

friendship_declined is signalled on success.

class friends.models.FriendshipManager
are_friends(user1, user2)

Indicate if user1 and user2 are friends.

Parameters:
  • user1 (User) – User to compare with user2.
  • user2 (User) – User to compare with user1.
Return type:

bool

befriend(user1, user2)

Establish friendship between user1 and user2.

Important

Instead of calling this method directly, FriendshipRequest.accept(), which calls this method, should be used.

Parameters:
  • user1 (User) – User to make friends with user2.
  • user2 (User) – User to make friends with user1.
friends_of(user, shuffle=False)

List friends of user.

Parameters:
  • user (User) – User to query friends.
  • shuffle (bool) – Optional. Default False.
Returns:

QuerySet containing friends of user.

unfriend(user1, user2)

Break friendship between user1 and user2.

Parameters:
  • user1 (User) – User to unfriend with user2.
  • user2 (User) – User to unfriend with user1.
class friends.models.Friendship(*args, **kwargs)

Represents the network of friendships.

friend_count()

Return the count of friends. This method is used in FriendshipAdmin.

Return type:int
friend_summary(count=7)

Return a string representation of friends. This method is used in FriendshipAdmin.

Parameters:count (int) – Maximum number of friends to include in the output.
Return type:unicode
class friends.models.UserBlocks(*args, **kwargs)

User‘s blocked by user.

block_count()

Return the count of blocks. This method is used in UserBlocksAdmin.

Return type:int
block_summary(count=7)

Return a string representation of blocks. This method is used in UserBlocksAdmin.

Parameters:count (int) – Maximum number of blocked users to include in the output.
Return type:unicode

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 by to_user.

Arguments sent with this signal:

sender
FriendshipRequest instance that is declined.

friendship_cancelled

friends.signals.friendship_cancelled

Sent when a FriendshipRequest is cancelled by from_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 created User.

See also

post_save built-in signal.

signals.create_userblocks_instance(sender, instance, created, raw, **kwargs)

Create a UserBlocks for newly created User.

See also

post_save built-in signal.