main.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # -*- coding: utf-8 -*-
  2. from openerp import http
  3. from openerp.http import request
  4. from werkzeug.wrappers import Response
  5. from werkzeug.datastructures import Headers
  6. from werkzeug.utils import redirect
  7. from gzip import GzipFile
  8. from StringIO import StringIO as IO
  9. import json
  10. import logging
  11. LOGGER = logging.getLogger(__name__)
  12. GZIP_COMPRESSION_LEVEL = 9
  13. class PrintEngineController(http.Controller):
  14. '''
  15. '''
  16. def make_info_log(self, log):
  17. LOGGER.info('[INFO] {}'.format(log))
  18. '''
  19. Make GZIP to JSON response
  20. '''
  21. def make_gzip_response(self, data=None, status=200):
  22. gzip_buffer = IO()
  23. with GzipFile(mode='wb', compresslevel=GZIP_COMPRESSION_LEVEL, fileobj=gzip_buffer) as gzip_file:
  24. gzip_file.write(json.dumps(data))
  25. contents = gzip_buffer.getvalue()
  26. gzip_buffer.close()
  27. headers = Headers()
  28. headers.add('Content-Encoding', 'gzip')
  29. headers.add('Vary', 'Accept-Encoding')
  30. headers.add('Content-Length', len(contents))
  31. return Response(contents, status=status, headers=headers, content_type='application/json')
  32. '''
  33. '''
  34. @http.route('/print_engine/update_printers', auth='user', type='json', methods=['POST'], cors='*')
  35. def printers_update(self, **kw):
  36. import pdb; pdb.set_trace()
  37. return True
  38. '''
  39. '''
  40. @http.route('/print_engine/socket_config', auth='user', type='json')
  41. def socket_config(self, **kw):
  42. settings_obj = request.env['print.engine.settings']
  43. settings = settings_obj.search([])
  44. return {
  45. 'host': settings.host or None,
  46. 'port': settings.port or None,
  47. 'path': settings.path or None
  48. }
  49. '''
  50. '''
  51. @http.route('/print_engine/get_pdf', auth='user', type='json')
  52. def get_pdf(self, **kw):
  53. import pdb; pdb.set_trace()
  54. return {
  55. 'pdf_data': None
  56. }