From 060ef9326849256a50a3ba5594af6b6ad3d0754f Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Tue, 11 Dec 2012 12:18:24 +0100 Subject: [PATCH 1/2] [IMP] show company logo in chrome bzr revid: chs@openerp.com-20121211111824-dj2ienybj2rxwhjj --- addons/web/__init__.py | 1 + addons/web/controllers/main.py | 39 ++++++++++++++++++++++++++--- addons/web/res_company.py | 24 ++++++++++++++++++ addons/web/static/src/css/base.css | 4 --- addons/web/static/src/css/base.sass | 4 --- addons/web/static/src/js/chrome.js | 5 ++++ addons/web/static/src/xml/base.xml | 2 +- 7 files changed, 67 insertions(+), 12 deletions(-) create mode 100644 addons/web/res_company.py diff --git a/addons/web/__init__.py b/addons/web/__init__.py index e01969ddcca..d9f2223f2c9 100644 --- a/addons/web/__init__.py +++ b/addons/web/__init__.py @@ -1,5 +1,6 @@ import http import controllers import cli +import res_company wsgi_postload = http.wsgi_postload diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py index 93e526093f1..abdbb1a00db 100644 --- a/addons/web/controllers/main.py +++ b/addons/web/controllers/main.py @@ -28,11 +28,13 @@ except ImportError: xlwt = None import openerp +import openerp.modules.registry from openerp.tools.translate import _ from .. import http openerpweb = http +_logger = logging.getLogger(__name__) #---------------------------------------------------------- # OpenERP Web helpers #---------------------------------------------------------- @@ -169,7 +171,6 @@ def module_installed_bypass_session(dbname): loadable = openerpweb.addons_manifest.keys() modules = {} try: - import openerp.modules.registry registry = openerp.modules.registry.RegistryManager.get(dbname) with registry.cursor() as cr: m = registry.get('ir.module.module') @@ -1202,9 +1203,10 @@ class Binary(openerpweb.Controller): except: pass return req.make_response(image_data, headers) - def placeholder(self, req): + + def placeholder(self, req, image='placeholder.png'): addons_path = openerpweb.addons_manifest['web']['addons_path'] - return open(os.path.join(addons_path, 'web', 'static', 'src', 'img', 'placeholder.png'), 'rb').read() + return open(os.path.join(addons_path, 'web', 'static', 'src', 'img', image), 'rb').read() @openerpweb.httprequest def saveas(self, req, model, field, id=None, filename_field=None, **kw): @@ -1312,6 +1314,37 @@ class Binary(openerpweb.Controller): args = {'erorr':e.faultCode.split('--')[1],'title':e.faultCode.split('--')[0]} return out % (simplejson.dumps(callback), simplejson.dumps(args)) + @openerpweb.httprequest + def company_logo(self, req, dbname=None): + # TODO add etag + uid = None + _logger.debug('session db = %r', req.session._db) + _logger.debug('session uid = %r', req.session._uid) + _logger.debug('param dbname = %r', dbname) + if req.session._db: + dbname = req.session._db + uid = req.session._uid + elif dbname is None: + dbname = db_monodb(req) + + if uid is None: + uid = openerp.SUPERUSER_ID + + _logger.debug('dbname = %r', dbname) + if not dbname: + image_data = self.placeholder(req, 'logo.png') + else: + registry = openerp.modules.registry.RegistryManager.get(dbname) + with registry.cursor() as cr: + user = registry.get('res.users').browse(cr, uid, uid) + image_data = user.company_id.logo_web.decode('base64') + + headers = [ + ('Content-Type', 'image/png'), + ('Content-Length', len(image_data)), + ] + return req.make_response(image_data, headers) + class Action(openerpweb.Controller): _cp_path = "/web/action" diff --git a/addons/web/res_company.py b/addons/web/res_company.py new file mode 100644 index 00000000000..523c3066502 --- /dev/null +++ b/addons/web/res_company.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python + +from openerp.osv import osv, fields +from openerp.tools import image_resize_image + +class Company(osv.Model): + _inherit = 'res.company' + + def _get_logo_web(self, cr, uid, ids, _field_name, _args, context=None): + result = dict.fromkeys(ids, False) + for record in self.browse(cr, uid, ids, context=context): + size = (180, None) + result[record.id] = image_resize_image(record.partner_id.image, size) + return result + + def _get_companies_from_partner(self, cr, uid, ids, context=None): + return self.pool['res.company'].search(cr, uid, [('partner_id', 'in', ids)], context=context) + + _columns = { + 'logo_web': fields.function(_get_logo_web, string="Logo Web", type="binary", store={ + 'res.company': (lambda s, c, u, i, x: i, ['partner_id'], 10), + 'res.partner': (_get_companies_from_partner, ['image'], 10), + }), + } diff --git a/addons/web/static/src/css/base.css b/addons/web/static/src/css/base.css index 0a4e2ad322f..382a7b3f1ab 100644 --- a/addons/web/static/src/css/base.css +++ b/addons/web/static/src/css/base.css @@ -1134,12 +1134,8 @@ width: 220px; display: block; text-align: center; - height: 70px; - line-height: 70px; } .openerp a.oe_logo img { - height: 40px; - width: 157px; margin: 14px 0; border: 0; } diff --git a/addons/web/static/src/css/base.sass b/addons/web/static/src/css/base.sass index e1789b0524c..b2a8d222e46 100644 --- a/addons/web/static/src/css/base.sass +++ b/addons/web/static/src/css/base.sass @@ -927,11 +927,7 @@ $sheet-padding: 16px width: 220px display: block text-align: center - height: 70px - line-height: 70px img - height: 40px - width: 157px margin: 14px 0 border: 0 .oe_footer diff --git a/addons/web/static/src/js/chrome.js b/addons/web/static/src/js/chrome.js index be88f89e711..b76b852a72f 100644 --- a/addons/web/static/src/js/chrome.js +++ b/addons/web/static/src/js/chrome.js @@ -1172,6 +1172,7 @@ instance.web.WebClient = instance.web.Client.extend({ show_application: function() { var self = this; self.toggle_bars(true); + self.update_logo(); self.menu = new instance.web.Menu(self); self.menu.replace(this.$el.find('.oe_menu_placeholder')); self.menu.on('menu_click', this, this.on_menu_action); @@ -1183,6 +1184,10 @@ instance.web.WebClient = instance.web.Client.extend({ self.set_title(); self.check_timezone(); }, + update_logo: function() { + var img = this.session.url('/web/binary/company_logo'); + this.$el.find('.oe_logo img').attr('src', '').attr('src', img); + }, check_timezone: function() { var self = this; return new instance.web.Model('res.users').call('read', [[this.session.uid], ['tz_offset']]).then(function(result) { diff --git a/addons/web/static/src/xml/base.xml b/addons/web/static/src/xml/base.xml index 5ad24a43a6a..a8715515588 100644 --- a/addons/web/static/src/xml/base.xml +++ b/addons/web/static/src/xml/base.xml @@ -439,7 +439,7 @@ - +