diff --git a/helios/models.py b/helios/models.py index bece7ca080c55f8c4f8a6ddf23700fa3376e70ab..2bc5742a282e13d5ad9041e91e45bc0945a08284 100644 --- a/helios/models.py +++ b/helios/models.py @@ -257,9 +257,10 @@ class Election(HeliosModel): # abort saving if bad URL if not (answer_url[:7] == "http://" or answer_url[:8]== "https://"): - return + return False self.questions = questions + return True def add_voters_file(self, uploaded_file): """ diff --git a/helios/templates/election_questions.html b/helios/templates/election_questions.html index d2262c4efaf9a1c0ee260ea881ae29e844147f5b..4f836463b7975ffd74e353710f568696b01b8571 100644 --- a/helios/templates/election_questions.html +++ b/helios/templates/election_questions.html @@ -26,7 +26,11 @@ function save_questions(callback) { $.post('./save_questions', {'questions_json' : $.toJSON(QUESTIONS), 'csrf_token': CSRF_TOKEN}, function(result) { - callback(); + if (result == "FAILURE") { + alert("The questions could not be saved. Please check that the URLs you entered are either http:// or https://"); + } else { + callback(); + } }); } @@ -106,7 +110,7 @@ function add_answer(el) { el = $(el); var num_answers = el.find('input.answer').length + 1; - el.find('tbody').append('<tr><th> </th><th>Answer #' + num_answers + '</th><td><input type="text" class="answer" name="answer_' + num_answers + '" size="70" /><br /><nobr>Link (optional): <input type="text" name="answer_url_' + num_answers + '" width="50%" /></nobr></td></tr>'); + el.find('tbody').append('<tr><th> </th><th>Answer #' + num_answers + '</th><td><input type="text" class="answer" name="answer_' + num_answers + '" size="70" /><br /><nobr>Link (optional, <tt>http</tt> or <tt>https</tt> only): <input type="text" name="answer_url_' + num_answers + '" width="50%" /></nobr></td></tr>'); } function add_answers(el, num) { diff --git a/helios/views.py b/helios/views.py index 17969db6d028c24ee4af5312b3fce1f301fc8bd6..f7975ee1333985247cdadb72ccc12371f645daca 100644 --- a/helios/views.py +++ b/helios/views.py @@ -941,11 +941,13 @@ def one_election_save_questions(request, election): check_csrf(request) questions = utils.from_json(request.POST['questions_json']) - election.save_questions_safely(questions) - election.save() - - # always a machine API - return SUCCESS + questions_saved = election.save_questions_safely(questions) + + if questions_saved: + election.save() + return SUCCESS + else: + return FAILURE @transaction.atomic @election_admin(frozen=False)