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.

60 lines
2.2 KiB

  1. # -*- encoding: utf-8 -*-
  2. ############################################################################
  3. #
  4. # OpenERP, Open Source Web Color
  5. # Copyright (C) 2012 Savoir-faire Linux (<http://www.savoirfairelinux.com>).
  6. # Copyright (C) 2014 Anybox <http://anybox.fr>
  7. # Copyright (C) 2015 Taktik SA <http://taktik.be>
  8. #
  9. # This program is free software: you can redistribute it and/or modify
  10. # it under the terms of the GNU General Public License as
  11. # published by the Free Software Foundation, either version 3 of the
  12. # License, or (at your option) any later version.
  13. #
  14. # This program is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. # GNU General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU General Public License
  20. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. #
  22. # @author Étienne Beaudry Auger <etienne.b.auger@savoirfairelinux.com>
  23. # @author Adil Houmadi <ah@taktik.be>
  24. #
  25. ##############################################################################
  26. import openerp.http as http
  27. from openerp.http import request
  28. from os.path import join, abspath, exists
  29. import mimetypes
  30. class JsColor(http.Controller):
  31. @http.route("/jscolor/<string:image>", type="http", auth="user")
  32. def jscolor(self, image):
  33. addons_path = http.addons_manifest['web_widget_color']['addons_path']
  34. path = join(
  35. addons_path,
  36. 'web_widget_color',
  37. 'static',
  38. 'lib',
  39. 'jscolor',
  40. image
  41. )
  42. if not exists(path):
  43. return request.not_found()
  44. try:
  45. image_file = open(abspath(path))
  46. image_data = image_file.read()
  47. image_file.close()
  48. mime_type = mimetypes.guess_type(path)
  49. if len(mime_type) > 1:
  50. mime_type = mime_type[0]
  51. else:
  52. return request.not_found()
  53. except:
  54. return request.not_found()
  55. headers = [
  56. ('Content-Type', '%s' % mime_type),
  57. ('Content-Length', len(image_data)),
  58. ]
  59. return request.make_response(image_data, headers)