keep the order of items intact in case of errors (e.g. "submitter" is empty)

This commit is contained in:
lars 2012-11-22 18:01:12 +00:00
parent 20fcc6c9a2
commit b9f09e273b

View file

@ -779,14 +779,19 @@ def vote_submission_order(bobo_request, hash_key=None, submitter=None,
data = {}
if submitter and is_spam_submitter_name(submitter, value_dict["errors"]):
data["submitter"] = submitter.strip()
if vote_order:
data["vote_order"] = vote_order
else:
data["vote_order"] = ""
if not vote_order:
vote_order = ""
data["vote_order"] = vote_order
poll_id = get_poll_id(hash_key)
if not poll_id is None:
poll = Poll.get(poll_id)
value_dict["poll"] = poll
# populate the "vote_order" list (to keep the order intact)
digest_dict = {}
for submission in ContentSubmission.selectBy(poll_id=poll.id):
digest_dict[submission.get_obfuscated_digest()] = submission
value_dict["vote_order"] = [digest_dict[content_hash]
for content_hash in vote_order.split()]
try:
data = forms.VoteSubmissionOrderForm.to_python(data)
except formencode.Invalid, errors_packed:
@ -804,15 +809,11 @@ def vote_submission_order(bobo_request, hash_key=None, submitter=None,
"Fehler: deine Wahl wurde bereits gespeichert."
else:
# store this order of items
digest_dict = {}
for submission in ContentSubmission.selectBy(poll_id=poll.id):
digest_dict[submission.get_obfuscated_digest()] = submission
vote_order = vote_order.split()
for index, digest in enumerate(vote_order):
if digest in digest_dict:
VoteOrder(submitter=submitter, priority=index,
content_submission_id=digest_dict[digest])
#value_dict["errors"]["submit"] = str(poll.get_ordered_submissions(submitter))
value_dict["submitter"] = submitter
return render("poll_details.html", input_data=data, **value_dict)
else: