summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorholyantony2015-07-15 11:05:01 +0530
committerholyantony2015-07-15 11:05:01 +0530
commit36867a956a4c8ccc80df53576d7d9ab21bf734f5 (patch)
tree55bec01cb1c1816f3003d2bc3b0b08688651c215
parent8346482d47f98be745466087b0bd5dc954f46cf4 (diff)
downloadFOSSEE-Forum-36867a956a4c8ccc80df53576d7d9ab21bf734f5.tar.gz
FOSSEE-Forum-36867a956a4c8ccc80df53576d7d9ab21bf734f5.tar.bz2
FOSSEE-Forum-36867a956a4c8ccc80df53576d7d9ab21bf734f5.zip
Subject:Vote Validation for answers
Description: 1. User cannot vote his/her answer
-rw-r--r--static/website/templates/get-question.html1
-rw-r--r--website/views.py76
2 files changed, 46 insertions, 31 deletions
diff --git a/static/website/templates/get-question.html b/static/website/templates/get-question.html
index 2c21c10..5b85866 100644
--- a/static/website/templates/get-question.html
+++ b/static/website/templates/get-question.html
@@ -373,6 +373,7 @@
$('div.ans-vote img.ans-vote-up').click(function(event) {
var id = event.target.id;
+
var vote_type = 'up';
if ($('img#'+id).hasClass('selected')) {
diff --git a/website/views.py b/website/views.py
index 8fd6b11..9c033df 100644
--- a/website/views.py
+++ b/website/views.py
@@ -380,46 +380,60 @@ def ans_vote_post(request):
vote_type = request.POST.get('type')
vote_action = request.POST.get('action')
-
+ answer_id = request.POST.get('id')
+ print "answer_id", answer_id
+
+ answer = Answer.objects.get(pk=answer_id)
cur_post = get_object_or_404(Answer, id=post_id)
userupvote = cur_post.userUpVotes.filter(id=request.user.id).count()
userdownvote = cur_post.userDownVotes.filter(id=request.user.id).count()
initial_votes = cur_post.userUpVotes.count() - cur_post.userDownVotes.count()
+ print "logged in user_id:", request.user.id,"Person who answered(user_id)", answer.uid
- # print "User Initial Upvote and Downvote: %d %d %s " % (thisuserupvote, thisuserdownvote, vote_action)
-
- #This loop is for voting
- if vote_action == 'vote':
- if (userupvote == 0) and (userdownvote == 0):
- if vote_type == 'up':
- cur_post.userUpVotes.add(request.user)
- elif vote_type == 'down':
- cur_post.userDownVotes.add(request.user)
- else:
- return HttpResponse("Error: Unknown vote-type passed.")
- else:
- return HttpResponse(initial_votes)
- #This loop is for canceling vote
- elif vote_action == 'recall-vote':
- if (vote_type == 'up') and (userupvote == 1):
- cur_post.userUpVotes.remove(request.user)
- elif (vote_type == 'down') and (userdownvote == 1):
- cur_post.userDownVotes.remove(request.user)
- else:
- # "Error - Unknown vote type or no vote to recall"
- return HttpResponse(initial_votes)
- else:
- return HttpResponse("Error: Bad Action.")
- num_votes = cur_post.userUpVotes.count() - cur_post.userDownVotes.count()
- cur_post.num_votes = num_votes
- cur_post.save()
-
- print "Num Votes: %s" % num_votes
+ if request.user.id != answer.uid:
+ print "Not same"
+ # print "User Initial Upvote and Downvote: %d %d %s " % (thisuserupvote, thisuserdownvote, vote_action)
- return HttpResponse(num_votes)
+ #This loop is for voting
+ if vote_action == 'vote':
+ if (userupvote == 0) and (userdownvote == 0):
+ if vote_type == 'up':
+ cur_post.userUpVotes.add(request.user)
+ elif vote_type == 'down':
+ cur_post.userDownVotes.add(request.user)
+ else:
+ return HttpResponse("Error: Unknown vote-type passed.")
+ else:
+ return HttpResponse(initial_votes)
+ #This loop is for canceling vote
+ elif vote_action == 'recall-vote':
+ if (vote_type == 'up') and (userupvote == 1):
+ cur_post.userUpVotes.remove(request.user)
+ elif (vote_type == 'down') and (userdownvote == 1):
+ cur_post.userDownVotes.remove(request.user)
+ else:
+ # "Error - Unknown vote type or no vote to recall"
+ return HttpResponse(initial_votes)
+ else:
+ return HttpResponse("Error: Bad Action.")
+
+ num_votes = cur_post.userUpVotes.count() - cur_post.userDownVotes.count()
+ cur_post.num_votes = num_votes
+ cur_post.save()
+
+ print "Num Votes: %s" % num_votes
+
+ return HttpResponse(num_votes)
+
+
+ else:
+ #else:
+ print "Same"
+
+ return HttpResponse(initial_votes)
# Notification Section
@login_required