Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions montage/juror_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
import html


MAX_RATINGS_SUBMIT = 100
MAX_RATINGS_SUBMIT = 100 # max ratings per bulk-submit batch (yesno/rating)
MAX_RANKING_TASKS = 2000 # max images in a single ranking round ballot
VALID_RATINGS = (0.0, 0.25, 0.5, 0.75, 1.0)
VALID_YESNO = (0.0, 1.0)

Expand Down Expand Up @@ -132,7 +133,7 @@ def get_tasks_from_round(user_dao, round_id, request):
juror_dao.confirm_active(round_id)
rnd = juror_dao.get_round(round_id)
if rnd.vote_method == 'ranking':
count = MAX_RATINGS_SUBMIT # TODO: better constant
count = MAX_RANKING_TASKS # ranking rounds must load all entries at once
tasks = juror_dao.get_tasks_from_round(round_id,
num=count,
offset=offset)
Expand Down Expand Up @@ -247,10 +248,7 @@ def submit_ratings(user_dao, request_dict):

r_dicts = request_dict['ratings']

if len(r_dicts) > MAX_RATINGS_SUBMIT:
raise InvalidAction('can submit up to 100 ratings at once, not %r'
% len(r_dicts))
elif not r_dicts:
if not r_dicts:
return {} # submitting no ratings = immediate return

review_map = {}
Expand Down Expand Up @@ -284,6 +282,11 @@ def submit_ratings(user_dao, request_dict):
rnd.confirm_active()
style = rnd.vote_method

# Enforce batch limit for rating/yesno — ranking rounds must submit all at once anyway
if style != 'ranking' and len(r_dicts) > MAX_RATINGS_SUBMIT:
raise InvalidAction('can submit up to %s ratings at once, not %r'
% (MAX_RATINGS_SUBMIT, len(r_dicts)))

# validation
if style == 'rating':
invalid = [r for r in id_map.values() if r not in VALID_RATINGS]
Expand Down