Esempio n. 1
0
def thank(request, review_id):
    if request.method == 'POST':
        thank = {
            'giver': request.session['_auth_user_id'],
            'review': review_id,
            'note': request.POST['text']
        }
        form = ThankForm(thank)
        if (form.is_valid() and not 
                Thank.objects.filter(giver=thank['giver'],
                                     review=thank['review'])):
            form.save()

    return redirect(request.META.get('HTTP_REFERER', None))
Esempio n. 2
0
def thank(user_id, review_id, note):
    """
    Creates a thank for a review if the user has previously not
    thanked the review and the user is not the writer of the
    review.  Returns False if the agree has been created successfully,
    otherwise returns an error message.
        user_id: id of the thanker (integer)
        review_id: id of the review (integer)
        note: thank you note (string)
    """
    if (Thank.objects.filter(giver=user_id, review=review_id)
            or user_id == Review.objects.get(pk=review_id).user_id):
        return "You can't thank your own review!"

    form = ThankForm({'giver': user_id, 'review': review_id, 'note': note})
    if form.is_valid():
        form.save()
        return False
    return "You already thanked this review!"
Esempio n. 3
0
def thank(user_id, review_id, note):
    """
    Creates a thank for a review if the user has previously not
    thanked the review and the user is not the writer of the
    review.  Returns False if the agree has been created successfully,
    otherwise returns an error message.
        user_id: id of the thanker (integer)
        review_id: id of the review (integer)
        note: thank you note (string)
    """
    if (Thank.objects.filter(giver=user_id, review=review_id) or
            user_id == Review.objects.get(pk=review_id).user_id):
        return "You can't thank your own review!"
    
    form = ThankForm({
        'giver': user_id,
        'review': review_id,
        'note': note
    })
    if form.is_valid():
        form.save()
        return False
    return "You already thanked this review!"