[ADD] survey_extra_fields, survey_base : copy modules from v16
This commit is contained in:
61
survey_extra_fields/controllers/main.py
Normal file
61
survey_extra_fields/controllers/main.py
Normal file
@@ -0,0 +1,61 @@
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import base64
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from odoo import http
|
||||
from odoo.http import request, content_disposition
|
||||
from odoo.addons.survey.controllers.main import Survey
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from werkzeug.wrappers import Response
|
||||
|
||||
|
||||
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: str,
|
||||
answer_token: str,
|
||||
line_id: int,
|
||||
**kwargs: Any
|
||||
) -> Response:
|
||||
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