Exemplo n.º 1
0
def view_product(request, slug):
    #generic product context
    product = Product.objects.get(slug=slug)
    images = Photo.objects.filter(product=product)
    average, amount = reviews_utils.get_average_for_instance(product)
    ctype = ContentType.objects.get(model="product")
    if average:
        average = (average / 5)*100
    else:
        average = 0

    #review form handling
    if request.method == "POST":
        form = ReviewAddForm(data=request.POST)
        # "Attach" the request to the form instance in order to get the user
        # out of the request within the clean method of the form (see above).
        form.request = request

        if form.is_valid():
            return save_review(request)
    else:
        form = ReviewAddForm()
    has_rated = reviews_utils.has_rated(request, product)
    tags = Tag.objects.get_for_object(product)
        
    return render_to_response('products/landing.html', {'product': product, 'images':images, 'average':average, 'amount':amount, 'ctype':ctype, "form" : form, "show_preview" : settings.REVIEWS_SHOW_PREVIEW, 'has_rated':has_rated, 'tags':tags}, context_instance=RequestContext(request))
Exemplo n.º 2
0
def reedit(request, template_name="reviews/review_form.html"):
    """Displays a form to edit a review. This is used if a reviewer re-edits
    a review after she has previewed it.
    """
    # get object
    content_type_id = request.POST.get("content_type_id")
    content_id = request.POST.get("content_id")

    ctype = ContentType.objects.get_for_id(content_type_id)
    object = ctype.get_object_for_this_type(pk=content_id)

    if reviews_utils.has_rated(request, object):
        return HttpResponseRedirect(reverse("reviews_already_rated"))

    scores = []
    for i, score in enumerate(SCORE_CHOICES):
        scores.append({
            "title": score[0],
            "value" : score[0],
            "current" : str(score[0]) == request.POST.get("score"),
            "z_index" : 10-i,
            "width" : (i+1) * 25,
        })

    form = ReviewAddForm(data=request.POST)
    return render_to_response(template_name, RequestContext(request, {
        "content_type_id" : content_type_id,
        "content_id" : content_id,
        "form" : form,
        "scores" : scores,
        "object" : object,
        "show_preview" : settings.REVIEWS_SHOW_PREVIEW,
    }))
Exemplo n.º 3
0
def reedit(request, template_name="reviews/review_form.html"):
    """Displays a form to edit a review. This is used if a reviewer re-edits
    a review after she has previewed it.
    """
    # get object
    content_type_id = request.POST.get("content_type_id")
    content_id = request.POST.get("content_id")

    ctype = ContentType.objects.get_for_id(content_type_id)
    obj = ctype.get_object_for_this_type(pk=content_id)

    if reviews_utils.has_rated(request, obj):
        return HttpResponseRedirect(reverse("reviews_already_rated"))

    scores = []
    for i, score in enumerate(SCORE_CHOICES):
        scores.append({
            "title": score[0],
            "value": score[0],
            "current": str(score[0]) == request.POST.get("score"),
            "z_index": 10 - i,
            "width": (i + 1) * 25,
        })

    form = ReviewAddForm(data=request.POST)
    return render(
        request, template_name, {
            "content_type_id": content_type_id,
            "content_id": content_id,
            "form": form,
            "scores": scores,
            "object": object,
            "show_preview": settings.REVIEWS_SHOW_PREVIEW,
        })
Exemplo n.º 4
0
def reviews_for_instance(context, instance):
    """
    """
    request = context.get("request")
    ctype = ContentType.objects.get_for_model(instance)
    has_rated = reviews_utils.has_rated(request, instance)
    reviews = reviews_utils.get_reviews_for_instance(instance)

    return {
        "reviews": reviews,
        "has_rated": has_rated,
        "content_id": instance.id,
        "content_type_id": ctype.id,
        "MEDIA_URL": context.get("MEDIA_URL")
    }
Exemplo n.º 5
0
def reviews_for_instance(context, instance):
    """
    """
    request = context.get("request")
    ctype = ContentType.objects.get_for_model(instance)
    has_rated = reviews_utils.has_rated(request, instance)
    reviews = reviews_utils.get_reviews_for_instance(instance)

    return {
        "reviews": reviews,
        "has_rated": has_rated,
        "content_id": instance.id,
        "content_type_id": ctype.id,
        "MEDIA_URL": context.get("MEDIA_URL")
    }
Exemplo n.º 6
0
def add_form(request,
             content_type_id,
             content_id,
             template_name="reviews/review_form.html"):
    """Displays the form to add a review. Dispatches the POST request of the
    form to save or reedit.
    """
    ctype = ContentType.objects.get_for_id(content_type_id)
    try:
        object = ctype.get_object_for_this_type(pk=content_id)
    except ctype.model_class().DoesNotExist:
        raise Http404

    if reviews_utils.has_rated(request, object):
        return HttpResponseRedirect(reverse("reviews_already_rated"))

    scores = []
    for i, score in enumerate(SCORE_CHOICES):
        scores.append({
            "title": score[0],
            "value": score[0],
            "z_index": 10 - i,
            "width": (i + 1) * 25,
        })

    if request.method == "POST":
        form = ReviewAddForm(data=request.POST)
        # "Attach" the request to the form instance in order to get the user
        # out of the request within the clean method of the form (see above).
        form.request = request
        if form.is_valid():
            if settings.REVIEWS_SHOW_PREVIEW:
                return preview(request)
            else:
                return save(request)
    else:
        form = ReviewAddForm()

    return render(
        request, template_name, {
            "content_type_id": content_type_id,
            "content_id": content_id,
            "object": object,
            "form": form,
            "scores": scores,
            "show_preview": settings.REVIEWS_SHOW_PREVIEW,
        })
Exemplo n.º 7
0
def add_form(request, content_type_id, content_id, template_name="reviews/review_form.html"):
    """Displays the form to add a review. Dispatches the POST request of the
    form to save or reedit.
    """
    ctype = ContentType.objects.get_for_id(content_type_id)

    try:
        object = ctype.get_object_for_this_type(pk=content_id)
    except ctype.model_class().DoesNotExist:
        raise Http404

    if reviews_utils.has_rated(request, object):
        return HttpResponseRedirect(reverse("reviews_already_rated"))

    scores = []
    for i, score in enumerate(SCORE_CHOICES):
        scores.append({
            "title": score[0],
            "value": score[0],
            "z_index": 10 - i,
            "width": (i + 1) * 25,
        })

    if request.method == "POST":
        form = ReviewAddForm(data=request.POST)
        # "Attach" the request to the form instance in order to get the user
        # out of the request within the clean method of the form (see above).
        form.request = request
        if form.is_valid():
            if settings.REVIEWS_SHOW_PREVIEW:
                return preview(request)
            else:
                return save(request)
    else:
        form = ReviewAddForm()

    return render_to_response(template_name, RequestContext(request, {
        "content_type_id": content_type_id,
        "content_id": content_id,
        "object": object,
        "form": form,
        "scores": scores,
        "show_preview": settings.REVIEWS_SHOW_PREVIEW,
    }))
Exemplo n.º 8
0
def add_form(request, content_type_id, content_id, template_name="reviews/review_form.html"):
    """Displays the form to add a review.
    """
    ctype = ContentType.objects.get_for_id(content_type_id)
    object = ctype.get_object_for_this_type(pk=content_id)

    if reviews_utils.has_rated(request, object):
        return HttpResponseRedirect(reverse("reviews_already_rated"))

    scores = []
    for i, score in enumerate(SCORE_CHOICES):
        scores.append({
            "title": score[0],
            "value" : score[0],
            "z_index" : 10-i,
            "width" : (i+1) * 25,
        })

    if request.method == "POST":
        form = ReviewAddForm(data=request.POST)
        form.request = request
        if form.is_valid():
            if settings.REVIEWS_SHOW_PREVIEW:
                return preview(request)
            else:
                return save(request)
    else:
        form = ReviewAddForm()

    return render_to_response(template_name, RequestContext(request, {
        "content_type_id" : content_type_id,
        "content_id" : content_id,
        "object" : object,
        "form" : form,
        "scores" : scores,
        "show_preview" : settings.REVIEWS_SHOW_PREVIEW,
    }))