def upvote_view(request): user = check_validation(request) comment = None print("upvote view") if user and request.method == 'POST': form = UpvoteForm(request.POST) if form.is_valid(): comment_id = int(form.cleaned_data.get('id')) comment = CommentModel.objects.filter(id=comment_id).first() print("upvoted not yet") if comment is not None: # print ' unliking post' print("upvoted") comment.upvote_num = +1 comment.save() print(comment.upvote_num) else: print('stupid mistake') #liked_msg = 'Unliked!' return redirect('/feed/') else: return redirect('/feed/')
def upvote_view(request): user = check_validation(request) comment = None print "upvote view" if user and request.method == 'POST': form = UpvoteForm(request.POST) if form.is_valid(): print form.cleaned_data comment_id = int(form.cleaned_data.get('id')) comment = Comment.objects.filter(id=comment_id).first() print "no upvote yet" if comment is not None: # print ' unliking post' print "upvoted" comment.upvote_number += 1 comment.save() print comment.upvote_number else: print 'some error!' # liked_msg = 'Unliked!' return redirect('/feed/') else: return redirect('/login/')
def Upvote_view(request): user = check_validation(request) if user and request.method == 'POST': form = UpvoteForm(request.POST) if form.is_valid(): response_data = {} comment_id = form.cleaned_data.get('comment') upvoted = UpvoteModel.objects.filter(comment_id=comment_id, user=user).first() if not upvoted: UpvoteModel.objects.create(comment=comment_id, user=user) response_data['subject'] = 'Upvoted' response_data['content'] = 'Comment upvoted by :' + form.cleaned_data.get('comment').user.name else: upvoted.delete() response_data['subject'] = 'Downvoted' response_data['content'] = 'Comment downvoted by ' + form.cleaned_data.get('comment').user.name return redirect('/feed/') else: return redirect('/login/')
def upvote_view(request): user = check_validation(request) if user and request.method == "POST": form = UpvoteForm(request.POST) if form.is_valid(): #fetching upvote ordownvote................................................................................. comment_id = form.cleaned_data.get('comment').id existing_vote = UpvoteModel.objects.filter(comment_id = comment_id, user=user).first() #checking forupvote or downvote............................................................................. if not existing_vote: UpvoteModel.objects.create(comment_id = comment_id, user=user) else: existing_vote.delete() #redirecting again to the feed view......................................................................... return redirect('/feed/') else: return redirect('/feed/') else: return redirect('/signup/')
def upvote_view(request): user = check_validation(request) if user and request.method == 'POST': form = UpvoteForm(request.POST) if form.is_valid(): post_id = form.cleaned_data.get('post').id comm_id = form.cleaned_data.get('comment').id existing_vote = UpvoteModel.objects.filter( post_id=post_id, user=user, comment_id=comm_id).first() if not existing_vote: print('created') UpvoteModel.objects.create(post_id=post_id, user=user, comment_id=comm_id) else: print('deleted') existing_vote.delete() return redirect('/feed/', {'drop': drop}) else: return redirect('/login/')
def upvote_view(request): user = check_validation(request) if request.method == 'POST': form = UpvoteForm(request.POST) if form.is_valid(): comment_id = form.cleaned_data.get('comment').id existing_upvote = UpvoteModel.objects.filter(comment_id=comment_id, user=user).first() if not existing_upvote: # if comment is not upvoted by current user UpvoteModel.objects.create(comment_id=comment_id, user=user) else: existing_upvote.delete() # devote comment return redirect('/feed/') else: return redirect('/login/') else: return redirect('/login/')