Exemplo n.º 1
0
def add_review(request):
    if request.method == 'POST':
        postdata = request.POST.copy()
        review_form = DestinationReviewForm(request.POST)
        if review_form.is_valid():

            destination_slug = request.POST.get('id_slug')
            d = get_object_or_404(Destination , slug = destination_slug)

            review = DestinationReview.objects.get_or_create(
                rating = review_form.data['rating'],
                title = review_form.data['title'],
                content = review_form.data['content'],
                user = request.user,
                destination = d
            )
            template = "destination/destination_review.html"
            html = render_to_string(template, {'review': review})
            response = simplejson.dumps({'success':'True', 'html': html})

        else:
                html = review_form.errors.as_ul()
                response = simplejson.dumps({'success':'False', 'html': html})

    if request.is_ajax():

        return HttpResponse(response,content_type="application/javascript")

    else:
        return HttpResponse(response,content_type='application/javascript; charset=utf-8')
Exemplo n.º 2
0
def add_review1(request , template_name = "destination/review.html"):

    if request.method == 'POST':
        postdata = request.POST.copy()
        review_form = DestinationReviewForm(request.POST)
        if review_form.is_valid():
            destination_slug = request.POST.get('id_slug')
            d = get_object_or_404(Destination , slug = destination_slug)

            review = DestinationReview.objects.get_or_create(
                rating = review_form.data['rating'],
                title = review_form.data['title'],
                content = review_form.data['content'],
                user = request.user,
                destination = d
            )
            return HttpResponseRedirect(d.get_absolute_url())
    else:
        review_form = DestinationReviewForm()
        variables = RequestContext(request,{'review_form':review_form})


    return render_to_response(template_name,locals(),context_instance = RequestContext(request))