[ADD] survey_extra_fields : file question type
Some checks failed
pre-commit / pre-commit (pull_request) Failing after 1m39s
Some checks failed
pre-commit / pre-commit (pull_request) Failing after 1m39s
This commit is contained in:
1
survey_extra_fields/controllers/__init__.py
Normal file
1
survey_extra_fields/controllers/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import main
|
||||
49
survey_extra_fields/controllers/main.py
Normal file
49
survey_extra_fields/controllers/main.py
Normal file
@@ -0,0 +1,49 @@
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
import base64
|
||||
|
||||
from odoo import http
|
||||
from odoo.http import request, content_disposition
|
||||
from odoo.addons.survey.controllers.main import Survey
|
||||
|
||||
|
||||
class SurveyExtraFieldsController(Survey):
|
||||
|
||||
@http.route(
|
||||
"/survey/file/<string:survey_token>/<string:answer_token>/<int:line_id>",
|
||||
type="http",
|
||||
auth="public",
|
||||
)
|
||||
def survey_file_download(self, survey_token, answer_token, line_id, **kwargs):
|
||||
survey = request.env["survey.survey"].sudo().search(
|
||||
[("access_token", "=", survey_token)], limit=1
|
||||
)
|
||||
if not survey:
|
||||
return request.not_found()
|
||||
|
||||
answer = request.env["survey.user_input"].sudo().search(
|
||||
[
|
||||
("survey_id", "=", survey.id),
|
||||
("access_token", "=", answer_token),
|
||||
],
|
||||
limit=1,
|
||||
)
|
||||
if not answer:
|
||||
return request.not_found()
|
||||
|
||||
line = request.env["survey.user_input.line"].sudo().browse(line_id)
|
||||
if not line.exists() or line.user_input_id != answer:
|
||||
return request.not_found()
|
||||
|
||||
if not line.value_file:
|
||||
return request.not_found()
|
||||
|
||||
file_content = base64.b64decode(line.value_file)
|
||||
filename = line.value_file_fname or "file"
|
||||
return request.make_response(
|
||||
file_content,
|
||||
headers=[
|
||||
("Content-Type", "application/octet-stream"),
|
||||
("Content-Disposition", content_disposition(filename)),
|
||||
],
|
||||
)
|
||||
Reference in New Issue
Block a user