The view of a single request.

def request_view(request, request_pk):
    '''
    The view of a single request.
    '''
    if request.is_ajax():
        if not request.user.is_authenticated():
            return HttpResponse(json.dumps(dict()),
                                content_type="application/json")

        try:
            relevant_request = Request.objects.get(pk=request_pk)
        except Request.DoesNotExist:
            return HttpResponse(json.dumps(dict()),
                                content_type="application/json")

        try:
            user_profile = UserProfile.objects.get(user=request.user)
        except UserProfile.DoesNotExist:
            return HttpResponse(json.dumps(dict()),
                                content_type="application/json")

        upvote = user_profile in relevant_request.upvotes.all()
        vote_form = VoteForm(
            request.POST if "upvote" in request.POST else None,
            profile=user_profile,
            request=relevant_request,
            )
        if vote_form.is_valid():
            vote_form.save()
            response = dict()
            response['vote_count_{pk}'.format(pk=request_pk)] = \
                relevant_request.upvotes.all().count()

            list_string = 'vote_list_{pk}'.format(pk=request_pk)
            vote_string = 'in_votes_{pk}'.format(pk=request_pk)
            count_string = 'vote_count_{pk}'.format(pk=request_pk)
            response[list_string], response[vote_string], \
                response[count_string] = build_ajax_votes(
                    relevant_request,
                    user_profile
                )
            return HttpResponse(json.dumps(response),
                                content_type="application/json")
        return HttpResponse(json.dumps(dict()),
                            content_type="application/json")

    relevant_request = get_object_or_404(Request, pk=request_pk)

    if relevant_request.private:
        if relevant_request.owner.user != request.user or \
          relevant_request.request_type.managers.filter(incumbent__user=request.user):
          return HttpResponseRedirect(
              reverse("managers:requests",
                      kwargs={"requestType": relevant_request.request_type.url_name}))

    userProfile = UserProfile.objects.get(user=request.user)
    request_responses = Response.objects.filter(request=relevant_request)
    relevant_managers = relevant_request.request_type.managers.filter(active=True)
    manager = any(i.incumbent == userProfile for i in relevant_managers)
    if manager:
        response_form = ManagerResponseForm(
            request.POST if "add_response" in request.POST else None,
            initial={'action': Response.NONE},
            profile=userProfile,
            request=relevant_request,
            )
    else:
        response_form = ResponseForm(
            request.POST if "add_response" in request.POST else None,
            profile=userProfile,
            request=relevant_request,
            prefix="response",
            )
    upvote = userProfile in relevant_request.upvotes.all()
    vote_form = VoteForm(
        request.POST if "upvote" in request.POST else None,
        profile=userProfile,
        request=relevant_request,
        )
    if response_form.is_valid():
        response_form.save()
        return HttpResponseRedirect(reverse('managers:view_request', kwargs={
            'request_pk': relevant_request.pk,
            }))
    if vote_form.is_valid():
        vote_form.save()
        return HttpResponseRedirect(reverse('managers:view_request', kwargs={
            'request_pk': relevant_request.pk,
            }))
    upvote = userProfile in relevant_request.upvotes.all()
    return render_to_response('view_request.html', {
        'page_name': "View Request",
        'relevant_request': relevant_request,
        'request_responses': request_responses,
        'upvote': upvote,
        'vote_form': vote_form,
        'response_form': response_form,
        'relevant_managers': relevant_managers,
        }, context_instance=RequestContext(request))