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.

52 lines
2.0 KiB

  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # Copyright (C) 2012 Agile Business Group sagl (<http://www.agilebg.com>)
  5. # Copyright (C) 2012 Domsense srl (<http://www.domsense.com>)
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU Affero General Public License as published
  9. # by the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU Affero General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Affero General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. ##############################################################################
  21. try:
  22. import json
  23. except ImportError:
  24. import simplejson as json
  25. import openerp.http as http
  26. from openerp.http import request
  27. from openerp.addons.web.controllers.main import ExcelExport
  28. class ExcelExportView(ExcelExport):
  29. def __getattribute__(self, name):
  30. if name == 'fmt':
  31. raise AttributeError()
  32. return super(ExcelExportView, self).__getattribute__(name)
  33. @http.route('/web/export/xls_view', type='http', auth='user')
  34. def index(self, data, token):
  35. data = json.loads(data)
  36. model = data.get('model', [])
  37. columns_headers = data.get('headers', [])
  38. rows = data.get('rows', [])
  39. return request.make_response(
  40. self.from_data(columns_headers, rows),
  41. headers=[
  42. ('Content-Disposition', 'attachment; filename="%s"'
  43. % self.filename(model)),
  44. ('Content-Type', self.content_type)
  45. ],
  46. cookies={'fileToken': token}
  47. )