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.

53 lines
2.0 KiB

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