123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- # -*- coding: utf-8 -*-
- from openerp import http
- from openerp.http import request
- from werkzeug.wrappers import Response
- from werkzeug.datastructures import Headers
- from werkzeug.utils import redirect
- from gzip import GzipFile
- from StringIO import StringIO as IO
- import json
- import logging
- LOGGER = logging.getLogger(__name__)
- GZIP_COMPRESSION_LEVEL = 9
- class PrintEngineController(http.Controller):
- '''
- '''
- def make_info_log(self, log):
- LOGGER.info('[INFO] {}'.format(log))
- '''
- Make GZIP to JSON response
- '''
- def make_gzip_response(self, 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))
-
- contents = gzip_buffer.getvalue()
- gzip_buffer.close()
- headers = Headers()
- headers.add('Content-Encoding', 'gzip')
- headers.add('Vary', 'Accept-Encoding')
- headers.add('Content-Length', len(contents))
- return Response(contents, status=status, headers=headers, content_type='application/json')
-
- '''
- '''
- @http.route('/print_engine/update_printers', auth='user', type='json', methods=['POST'], cors='*')
- def printers_update(self, **kw):
- import pdb; pdb.set_trace()
- return True
- '''
- '''
- @http.route('/print_engine/socket_config', auth='user', type='json')
- def socket_config(self, **kw):
- settings_obj = request.env['print.engine.settings']
- settings = settings_obj.search([])
-
- return {
- 'host': settings.host or None,
- 'port': settings.port or None,
- 'path': settings.path or None
- }
- '''
- '''
- @http.route('/print_engine/get_pdf', auth='user', type='json')
- def get_pdf(self, **kw):
- import pdb; pdb.set_trace()
- return {
- 'pdf_data': None
- }
|