activation_required self_protect def add_friend request user_id Ask us

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
@activation_required()
@self_protect()
def add_friend(request, user_id):
"""
Ask user for friendship confirmation, ignore if already in friends or sent
"""
user = get_object_or_404(Profile, pk=user_id)
if not get_object_or_None(FriendConfirmation, sender=request.user, recipient=user) and not user in request.user.friends.all():
confirmation = FriendConfirmation(sender=request.user, recipient=user)
confirmation.save()
flash.notice_next(u"%s have to confirm friendship, we have send notification" % user.display_name)
else:
flash.notice_next(u"%s is already your friend or confirmation already sent" % user.display_name)
return HttpResponseRedirect(request.user.show_url())