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.

33 lines
1.1 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2017 Onestein (<http://www.onestein.eu>)
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from odoo import http
  5. from json import dumps
  6. class ChatterPasteController(http.Controller):
  7. @http.route('/web_chatter_paste/upload_attachment', type='http',
  8. auth="user")
  9. def upload_attachment(self, callback, model, id, filename, mimetype,
  10. content):
  11. request = http.request
  12. model_obj = request.env['ir.attachment']
  13. out = """<script language="javascript" type="text/javascript">
  14. var win = window.top.window;
  15. win.jQuery(win).trigger(%s, %s);
  16. </script>"""
  17. attachment = model_obj.create({
  18. 'name': filename,
  19. 'datas': content,
  20. 'datas_fname': filename,
  21. 'res_model': model,
  22. 'res_id': int(id)
  23. })
  24. args = {
  25. 'filename': filename,
  26. 'mimetype': mimetype,
  27. 'id': attachment.id
  28. }
  29. return out % (dumps(callback), dumps(args))