Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added find friends view.

  • Loading branch information...
commit cdf126bf706abad5805dcc0155233fec3d3b1239 1 parent 00e7e15
Alex Gaynor alex authored

Showing 1 changed file with 22 additions and 1 deletion. Show diff stats Hide diff stats

  1. +22 1 friends/views.py
23 friends/views.py
... ... @@ -1 +1,22 @@
1   -# Create your views here.
  1 +from django.contrib.auth.decorators import login_required
  2 +from django.contrib.auth.models import User
  3 +from django.http import HttpResponseRedirect
  4 +from django.shortcuts import render_to_response, get_object_or_404
  5 +from django.template import RequestContext
  6 +
  7 +from friends.models import FriendshipInvitation
  8 +
  9 +
  10 +@login_required
  11 +def find_friends(request):
  12 + if request.method == "POST":
  13 + u = get_object_or_404(User, pk=request.POST["user_id"])
  14 + FriendshipInvitation.create_friendship_request(request.user, u)
  15 + return HttpResponseRedirect(request.path)
  16 + elif request.GET.get("q"):
  17 + friends = User.objects.filter(username__icontains=request.GET["q"])
  18 + else:
  19 + friends = None
  20 + return render_to_response("friends/find_friends.html", {
  21 + "friends": friends,
  22 + }, context_instance=RequestContext(request))

0 comments on commit cdf126b

Please sign in to comment.
Something went wrong with that request. Please try again.