[IMP] survey_extra_fields : handle file question on page navigation
Some checks failed
pre-commit / pre-commit (pull_request) Has been cancelled

(cherry picked from commit d0afa2310d)
This commit is contained in:
2026-06-10 17:23:31 +02:00
parent 3cce144be2
commit 7e28a79d63
6 changed files with 149 additions and 16 deletions

View File

@@ -23,14 +23,25 @@ class SurveyUserInput(models.Model):
("user_input_id", "=", self.id),
("question_id", "=", question.id),
])
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)