Show - Convert positive to a boolean

This commit is contained in:
Evert Prants 2017-11-11 11:26:26 +02:00
parent 528e95fc7b
commit c3eff9f88a
Signed by: evert
GPG Key ID: 1688DA83D222D0B5

View File

@ -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('<h1>Error</h1><p>You need to be logged in to vote. Please <a href=/login>log in</a></p>')
@ -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()