1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- # -*- coding: utf-8 -*-
- from openerp import http
- from werkzeug.wrappers import Response
- from werkzeug.datastructures import Headers
- from gzip import GzipFile
- from StringIO import StringIO as IO
- import simplejson as json
- import helpers as hp
- import logging
- LOGGER = logging.getLogger(__name__)
- GZIP_COMPRESSION_LEVEL = 9
- def make_gzip_response(data=None, status=200):
- gzip_buffer = IO()
- with GzipFile(mode='wb', compresslevel=GZIP_COMPRESSION_LEVEL, fileobj=gzip_buffer) as gzip_file:
- gzip_file.write(json.dumps(data))
- value = gzip_buffer.getvalue()
- gzip_buffer.close()
- headers = Headers()
- headers.add('Content-Encoding', 'gzip')
- headers.add('Vary', 'Accept-Encoding')
- headers.add('Content-Length', len(value))
- return Response(value, status=status, headers=headers, content_type='application/json')
- class DashboardController3(http.Controller):
- @http.route('/dashboard-widgets3', auth='user', methods=['GET', 'POST'])
- def getWidgetList(self, **kw):
- return make_gzip_response({
- 'widgets': hp.get_widget_list(),
- })
- @http.route('/dashboard-RankingMorosos', auth='user', methods=['GET', 'POST'])
- def getRankingMorosos(self, **kw):
- return make_gzip_response({
- 'company': hp.get_company_info(),
- 'partner': hp.get_res_partner(),
- 'orders':hp.get_pos_order_widget(),
- 'invoices':hp.get_account_invoice(),
- 'moveLine':hp.get_account_move_line(),
- })
|