def follow(request, username):
    follower = request.user

    follow_form = FollowForm({'username':username})
    if not follow_form.is_valid():
        raise Http404()

    followee = User.objects.get(username=follow_form.cleaned_data['username'])

    follower.userprofile.following.add(followee)

    follower.userprofile.save()

    on_follow(follower, followee)

    return redirect(reverse('follower_stream'))
def handle_response(response, user, errorlogger):

	if 'data' in response:

		new_data = response['data']
		script = user.userprofile.script
		script.data = new_data
		script.save()


	if 'posts' in response:
		for post_info in response['posts']:
			if 'content' not in post_info:
				errorlogger.log_error("Error: Invalid post: "+json.dumps(post_info))
				break

			content = post_info['content']

			post_form = PostForm({'content':content})
			if not post_form.is_valid():
				errorlogger.log_error("Error: Invalid post: "+json.dumps(post_info))
				break

			new_post = Post(content=post_form.cleaned_data['content'], user=user)
			new_post.save()
	
	if 'comments' in response:
		for comment_info in response['comments']:
			if ('content' not in comment_info) or ('post_id' not in comment_info):
				errorlogger.log_error("Error: Invalid comment: "+json.dumps(comment_info))
				break

			post_id = comment_info['post_id']
			content = comment_info['content']
			comment_form = CommentForm({'post':post_id,'content':content})
			if not comment_form.is_valid():
				errorlogger.log_error("Error: Invalid comment: "+json.dumps(comment_info))
				break

			new_comment = Comment(content=comment_form.cleaned_data['content'],
									post=comment_form.cleaned_data['post'],
									user=user)
			new_comment.save()

	if 'follow' in response:
		for followee_username in response['follow']:
			follow_form = FollowForm({'username':followee_username})
			if not follow_form.is_valid():
				errorlogger.log_error("Error: Invalid followee: "+str(followee_username))
				break

			followee = User.objects.get(username=follow_form.cleaned_data['username'])
			user.userprofile.following.add(followee)

			user.userprofile.save()

	if 'unfollow' in response:
		for target in response['unfollow']:
			unfollow_form = UnfollowForm({'username':target})
			if not unfollow_form.is_valid():
				errorlogger.log_error("Error: Invalid unfollow target: "+str(target))
				break

			target_user = User.objects.get(username=unfollow_form.cleaned_data['username'])
			user.userprofile.following.remove(target_user)

			user.userprofile.save()

	if 'log' in response:
		for entry in response['log']:
			errorlogger.log_error(str(entry))