コード例 #1
0
ファイル: views.py プロジェクト: Fandekasp/django-critic
def render_rating(request, content_type_id, object_id):
    """
    Returns the rendered rating template.
    """
    ctype = get_object_or_404(ContentType, pk=content_type_id)
    
    obj = get_object_or_404(ctype.model_class(), pk=object_id)
    
    # The only extra context we need to retreive is the user rating, if
    # the user is authenticated.
    user_rating = None
    if request.user.is_authenticated():
        user_rating = RatingData.objects.user_rating(obj, request.user)
    
    rendered_content = render(obj, **{'user_rating': user_rating})
    return HttpResponse(rendered_content)
コード例 #2
0
    def render(self, context):
        try:
            obj = Variable(self.obj).resolve(context)
        except:
            return ""

        extra_context = {}
        try:
            # Retrieve the request.user
            user = Variable('user').resolve(context)
            if user.is_authenticated():
                extra_context['user_rating'] = RatingData.objects.user_rating(
                    obj, user)
            # Add csrf_token to form
            csrf = Variable('csrf_token').resolve(context)
            extra_context['csrf_token'] = csrf
        except Exception:
            pass

        return render(obj, **extra_context)