You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
3.2 KiB

7 years ago
7 years ago
7 years ago
7 years ago
6 years ago
7 years ago
6 years ago
7 years ago
7 years ago
6 years ago
7 years ago
6 years ago
7 years ago
6 years ago
  1. ###################################################################################
  2. #
  3. # Copyright (C) 2018 MuK IT GmbH
  4. #
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU Affero General Public License as
  7. # published by the Free Software Foundation, either version 3 of the
  8. # License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU Affero General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU Affero General Public License
  16. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. #
  18. ###################################################################################
  19. import logging
  20. from werkzeug import utils
  21. from werkzeug import wrappers
  22. from odoo import http
  23. from odoo.http import request
  24. _logger = logging.getLogger(__name__)
  25. def lobject_content(xmlid=None, model=None, id=None, field='content', unique=False,
  26. filename=None, filename_field='content_fname', download=False, mimetype=None,
  27. default_mimetype='application/octet-stream', access_token=None, env=None):
  28. return request.registry['ir.http'].lobject_content(
  29. xmlid=xmlid, model=model, id=id, field=field, unique=unique, filename=filename,
  30. filename_field=filename_field, download=download, mimetype=mimetype,
  31. default_mimetype=default_mimetype, access_token=access_token, env=env)
  32. class LargeObjectController(http.Controller):
  33. @http.route(['/web/lobject',
  34. '/web/lobject/<string:xmlid>',
  35. '/web/lobject/<string:xmlid>/<string:filename>',
  36. '/web/lobject/<int:id>',
  37. '/web/lobject/<int:id>/<string:filename>',
  38. '/web/lobject/<int:id>-<string:unique>',
  39. '/web/lobject/<int:id>-<string:unique>/<string:filename>',
  40. '/web/lobject/<string:model>/<int:id>/<string:field>',
  41. '/web/lobject/<string:model>/<int:id>/<string:field>/<string:filename>'], type='http', auth="public")
  42. def content_lobject(self, xmlid=None, model=None, id=None, field='content',
  43. filename=None, filename_field='content_fname', unique=None, mimetype=None,
  44. download=None, data=None, token=None, access_token=None):
  45. status, headers, content = lobject_content(
  46. xmlid=xmlid, model=model, id=id, field=field, unique=unique, filename=filename,
  47. filename_field=filename_field, download=download, mimetype=mimetype,
  48. access_token=access_token)
  49. if status == 304:
  50. response = wrappers.Response(status=status, headers=headers)
  51. elif status == 301:
  52. return utils.redirect(content, code=301)
  53. elif status != 200:
  54. response = request.not_found()
  55. else:
  56. headers.append(('Content-Length', content.seek(0, 2)))
  57. content.seek(0, 0)
  58. response = wrappers.Response(content, headers=headers, status=status, direct_passthrough=True)
  59. if token:
  60. response.set_cookie('fileToken', token)
  61. return response