From c3eff9f88a85ec947bda60e9a3f541f61ee5e3c4 Mon Sep 17 00:00:00 2001 From: Evert Date: Sat, 11 Nov 2017 11:26:26 +0200 Subject: [PATCH] Show - Convert positive to a boolean --- Show/views.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Show/views.py b/Show/views.py index 3512549..d8a5afb 100644 --- a/Show/views.py +++ b/Show/views.py @@ -84,6 +84,9 @@ class EpisodeView(TemplateView): # /show/{{abbr}}/vote/{{submission id}}/{{positive == 1}} class SubmissionVoteSubmit(View): def get (self, req, abbreviation, subid, positive): + # Convert positive parameter into a boolean + pos_bool = int(positive) == 1 + # Check for login status if not req.session['user_id']: r = HttpResponse('

Error

You need to be logged in to vote. Please log in

') @@ -108,8 +111,8 @@ class SubmissionVoteSubmit(View): # Allow changing a vote from positive to negative or vice-versa. Delete vote if its a re-vote vote = submission.votes.filter(user=user,submission__id=submission.id).first() if vote: - if not vote.positive == (int(positive) == 1): - vote.positive = int(positive) == 1 + if not vote.positive == pos_bool: + vote.positive = pos_bool vote.save() else: vote.delete() @@ -117,7 +120,7 @@ class SubmissionVoteSubmit(View): new_vote = SubmissionVote( user=user, submission=submission, - positive=int(positive) == 1 + positive=pos_bool ) new_vote.save()