Show - Convert positive to a boolean
This commit is contained in:
parent
528e95fc7b
commit
c3eff9f88a
@ -84,6 +84,9 @@ class EpisodeView(TemplateView):
|
|||||||
# /show/{{abbr}}/vote/{{submission id}}/{{positive == 1}}
|
# /show/{{abbr}}/vote/{{submission id}}/{{positive == 1}}
|
||||||
class SubmissionVoteSubmit(View):
|
class SubmissionVoteSubmit(View):
|
||||||
def get (self, req, abbreviation, subid, positive):
|
def get (self, req, abbreviation, subid, positive):
|
||||||
|
# Convert positive parameter into a boolean
|
||||||
|
pos_bool = int(positive) == 1
|
||||||
|
|
||||||
# Check for login status
|
# Check for login status
|
||||||
if not req.session['user_id']:
|
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>')
|
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
|
# 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()
|
vote = submission.votes.filter(user=user,submission__id=submission.id).first()
|
||||||
if vote:
|
if vote:
|
||||||
if not vote.positive == (int(positive) == 1):
|
if not vote.positive == pos_bool:
|
||||||
vote.positive = int(positive) == 1
|
vote.positive = pos_bool
|
||||||
vote.save()
|
vote.save()
|
||||||
else:
|
else:
|
||||||
vote.delete()
|
vote.delete()
|
||||||
@ -117,7 +120,7 @@ class SubmissionVoteSubmit(View):
|
|||||||
new_vote = SubmissionVote(
|
new_vote = SubmissionVote(
|
||||||
user=user,
|
user=user,
|
||||||
submission=submission,
|
submission=submission,
|
||||||
positive=int(positive) == 1
|
positive=pos_bool
|
||||||
)
|
)
|
||||||
new_vote.save()
|
new_vote.save()
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user