keep the order of items intact in case of errors (e.g. "submitter" is empty)
This commit is contained in:
parent
20fcc6c9a2
commit
b9f09e273b
1 changed files with 9 additions and 8 deletions
|
@ -779,14 +779,19 @@ def vote_submission_order(bobo_request, hash_key=None, submitter=None,
|
||||||
data = {}
|
data = {}
|
||||||
if submitter and is_spam_submitter_name(submitter, value_dict["errors"]):
|
if submitter and is_spam_submitter_name(submitter, value_dict["errors"]):
|
||||||
data["submitter"] = submitter.strip()
|
data["submitter"] = submitter.strip()
|
||||||
if vote_order:
|
if not vote_order:
|
||||||
data["vote_order"] = vote_order
|
vote_order = ""
|
||||||
else:
|
data["vote_order"] = vote_order
|
||||||
data["vote_order"] = ""
|
|
||||||
poll_id = get_poll_id(hash_key)
|
poll_id = get_poll_id(hash_key)
|
||||||
if not poll_id is None:
|
if not poll_id is None:
|
||||||
poll = Poll.get(poll_id)
|
poll = Poll.get(poll_id)
|
||||||
value_dict["poll"] = poll
|
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:
|
try:
|
||||||
data = forms.VoteSubmissionOrderForm.to_python(data)
|
data = forms.VoteSubmissionOrderForm.to_python(data)
|
||||||
except formencode.Invalid, errors_packed:
|
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."
|
"Fehler: deine Wahl wurde bereits gespeichert."
|
||||||
else:
|
else:
|
||||||
# store this order of items
|
# 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()
|
vote_order = vote_order.split()
|
||||||
for index, digest in enumerate(vote_order):
|
for index, digest in enumerate(vote_order):
|
||||||
if digest in digest_dict:
|
if digest in digest_dict:
|
||||||
VoteOrder(submitter=submitter, priority=index,
|
VoteOrder(submitter=submitter, priority=index,
|
||||||
content_submission_id=digest_dict[digest])
|
content_submission_id=digest_dict[digest])
|
||||||
#value_dict["errors"]["submit"] = str(poll.get_ordered_submissions(submitter))
|
|
||||||
value_dict["submitter"] = submitter
|
value_dict["submitter"] = submitter
|
||||||
return render("poll_details.html", input_data=data, **value_dict)
|
return render("poll_details.html", input_data=data, **value_dict)
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in a new issue