Parse rating int in view handler.

Activity already represents rating as an int in the json.
This commit is contained in:
Adam Kelly 2020-04-02 10:25:47 +01:00
parent cceb433620
commit 5bcf65a8a1
2 changed files with 3 additions and 4 deletions

View file

@ -30,10 +30,9 @@ def create_review(user, book, name, content, rating):
content = sanitize(content) content = sanitize(content)
# no ratings outside of 0-5 # no ratings outside of 0-5
try: if rating:
rating = int(rating)
rating = rating if 1 <= rating <= 5 else None rating = rating if 1 <= rating <= 5 else None
except ValueError: else:
rating = None rating = None
return models.Review.objects.create( return models.Review.objects.create(

View file

@ -172,7 +172,7 @@ def review(request):
# TODO: validation, htmlification # TODO: validation, htmlification
name = form.data.get('name') name = form.data.get('name')
content = form.data.get('content') content = form.data.get('content')
rating = form.data.get('rating') rating = form.cleaned_data.get('rating')
# throws a value error if the book is not found # throws a value error if the book is not found
book = get_or_create_book(book_identifier) book = get_or_create_book(book_identifier)