Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added find friends view.

  • Loading branch information...
commit cdf126bf706abad5805dcc0155233fec3d3b1239 1 parent 00e7e15
@alex alex authored
Showing with 22 additions and 1 deletion.
  1. +22 −1 friends/views.py
View
23 friends/views.py
@@ -1 +1,22 @@
-# Create your views here.
+from django.contrib.auth.decorators import login_required
+from django.contrib.auth.models import User
+from django.http import HttpResponseRedirect
+from django.shortcuts import render_to_response, get_object_or_404
+from django.template import RequestContext
+
+from friends.models import FriendshipInvitation
+
+
+@login_required
+def find_friends(request):
+ if request.method == "POST":
+ u = get_object_or_404(User, pk=request.POST["user_id"])
+ FriendshipInvitation.create_friendship_request(request.user, u)
+ return HttpResponseRedirect(request.path)
+ elif request.GET.get("q"):
+ friends = User.objects.filter(username__icontains=request.GET["q"])
+ else:
+ friends = None
+ return render_to_response("friends/find_friends.html", {
+ "friends": friends,
+ }, context_instance=RequestContext(request))
Please sign in to comment.
Something went wrong with that request. Please try again.