main.py 694 B

123456789101112131415161718192021222324
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. import json
  4. from odoo import http
  5. from odoo.http import request
  6. from odoo.tools import misc
  7. class ImportController(http.Controller):
  8. @http.route('/base_import/set_file', methods=['POST'])
  9. def set_file(self, file, import_id, jsonp='callback'):
  10. import_id = int(import_id)
  11. written = request.env['base_import.import'].browse(import_id).write({
  12. 'file': file.read(),
  13. 'file_name': file.filename,
  14. 'file_type': file.content_type,
  15. })
  16. return 'window.top.%s(%s)' % (misc.html_escape(jsonp), json.dumps({'result': written}))