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))
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!"
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!"