[IMP] survey_extra_fields : handle file question on page navigation
Some checks failed
pre-commit / pre-commit (pull_request) Failing after 1m40s
Some checks failed
pre-commit / pre-commit (pull_request) Failing after 1m40s
* Show a stored file (after navigating back) the same way as a freshly selected one: a "filename + Remove file" chip, input hidden until removal. * Keep the stored file when a page is re-submitted without a new selection (instead of overwriting it with a skipped answer). * "Remove file" now sends a sentinel to actually delete the stored file, so the removal persists across navigation.
This commit is contained in:
@@ -31,14 +31,25 @@ class SurveyUserInput(models.Model):
|
||||
])
|
||||
if old_answers and not overwrite_existing:
|
||||
raise UserError(_("This answer cannot be overwritten."))
|
||||
if not answer and any(line.value_file for line in old_answers):
|
||||
# No new file was submitted: a file input cannot be pre-filled
|
||||
# by the browser when navigating back to a previous page, so an
|
||||
# empty answer here does not mean the user removed their file.
|
||||
# Keep the previously uploaded file instead of overwriting it
|
||||
# with a skipped answer.
|
||||
return
|
||||
vals = {
|
||||
"user_input_id": self.id,
|
||||
"question_id": question.id,
|
||||
"skipped": False,
|
||||
"answer_type": "file",
|
||||
}
|
||||
if answer:
|
||||
file_data = json.loads(answer)
|
||||
file_data = json.loads(answer) if answer else {}
|
||||
if file_data.get("cleared"):
|
||||
# The user explicitly removed the file: drop the stored data and
|
||||
# mark the line as skipped.
|
||||
vals.update(answer_type=None, skipped=True, value_file=False, value_file_fname=False)
|
||||
elif file_data:
|
||||
file_b64 = file_data.get("data", "")
|
||||
file_name = file_data.get("name", "")
|
||||
self._check_file_constraints(question, file_b64, file_name)
|
||||
|
||||
Reference in New Issue
Block a user