Permalink
Browse files

Added a view for responding to friendship requests.

  • Loading branch information...
1 parent e206f01 commit dbfc21689286e38a5f286abe23c0dc0d4c0ec212 @alex alex committed Oct 27, 2009
Showing with 17 additions and 1 deletion.
  1. +17 −1 friends/views.py
View
@@ -2,7 +2,7 @@
from django.contrib.auth.models import User
from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect
-from django.shortcuts import render_to_response, get_object_or_404
+from django.shortcuts import render_to_response, get_object_or_404, redirect
from django.template import RequestContext
from friends.models import FriendshipInvitation
@@ -18,6 +18,22 @@ def find_friends(request):
"users": users,
}, context_instance=RequestContext(request))
+@login_required
+def respond_to_friendship_invitation(request, invitation_id, redirect_to_view=None):
+ inv = get_object_or_404(FriendshipInvitation, to_user=request.user,
+ pk=invitation_id)
+ response = request.GET.get("response", "a")
+ if response == "a":
+ inv.accept()
+ elif response == "d":
+ inv.decline()
+ else:
+ raise ValueError("%s isn't a valid response to a friendship request %s" % response)
+ if redirect_to_view is not None:
+ return redirect(redirect_to_view)
+ return HttpResponseRedirect(request.META["HTTP_REFERER"])
+
+
"""
@login_required
def add_friend(request):

0 comments on commit dbfc216

Please sign in to comment.