Пример #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))
Пример #2
0
def average_for_instance(context, instance):
    """
    """
    average, amount = reviews_utils.get_average_for_instance(instance)
    return {
        "average": average,
        "amount": amount,
    }
Пример #3
0
def average_for_instance(context, instance):
    """
    """
    average, amount = reviews_utils.get_average_for_instance(instance)
    return {
        "average": average,
        "amount": amount,
    }