Christophe (OpenERP) has proposed merging lp:~openerp-dev/openerp-web/trunk-company_logo-chs into lp:openerp-web.
Requested reviews: OpenERP R&D Web Team (openerp-dev-web) For more details, see: https://code.launchpad.net/~openerp-dev/openerp-web/trunk-company_logo-chs/+merge/139169 -- https://code.launchpad.net/~openerp-dev/openerp-web/trunk-company_logo-chs/+merge/139169 Your team OpenERP R&D Team is subscribed to branch lp:~openerp-dev/openerp-web/trunk-company_logo-chs.
=== modified file 'addons/web/__init__.py' --- addons/web/__init__.py 2012-12-09 02:48:10 +0000 +++ addons/web/__init__.py 2012-12-11 11:25:30 +0000 @@ -1,5 +1,6 @@ import http import controllers import cli +import res_company wsgi_postload = http.wsgi_postload === modified file 'addons/web/controllers/main.py' --- addons/web/controllers/main.py 2012-12-11 10:33:57 +0000 +++ addons/web/controllers/main.py 2012-12-11 11:25:30 +0000 @@ -28,11 +28,13 @@ 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 @@ 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 @@ 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 @@ 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" === added file 'addons/web/res_company.py' --- addons/web/res_company.py 1970-01-01 00:00:00 +0000 +++ addons/web/res_company.py 2012-12-11 11:25:30 +0000 @@ -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), + }), + } === modified file 'addons/web/static/src/css/base.css' --- addons/web/static/src/css/base.css 2012-12-03 18:42:14 +0000 +++ addons/web/static/src/css/base.css 2012-12-11 11:25:30 +0000 @@ -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; } === modified file 'addons/web/static/src/css/base.sass' --- addons/web/static/src/css/base.sass 2012-12-03 18:42:14 +0000 +++ addons/web/static/src/css/base.sass 2012-12-11 11:25:30 +0000 @@ -927,11 +927,7 @@ width: 220px display: block text-align: center - height: 70px - line-height: 70px img - height: 40px - width: 157px margin: 14px 0 border: 0 .oe_footer === modified file 'addons/web/static/src/js/chrome.js' --- addons/web/static/src/js/chrome.js 2012-12-11 02:13:38 +0000 +++ addons/web/static/src/js/chrome.js 2012-12-11 11:25:30 +0000 @@ -1172,6 +1172,7 @@ 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 @@ 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) { === modified file 'addons/web/static/src/xml/base.xml' --- addons/web/static/src/xml/base.xml 2012-12-10 12:54:23 +0000 +++ addons/web/static/src/xml/base.xml 2012-12-11 11:25:30 +0000 @@ -439,7 +439,7 @@ <tr> <td class="oe_leftbar" valign="top"> <t t-set="debug" t-value="__debug__ ? '&debug' : ''"/> - <a class="oe_logo" t-attf-href="/?ts=#{Date.now()}#{debug}"><img t-att-src='_s + "/web/static/src/img/logo.png"'/></a> + <a class="oe_logo" t-attf-href="/?ts=#{Date.now()}#{debug}"><img t-att-src='widget.session.url("/web/binary/company_logo")'/></a> <div class="oe_secondary_menus_container"/> <div class="oe_footer"> Powered by <a href="http://www.openerp.com" target="_blank"><span>OpenERP</span></a>
_______________________________________________ Mailing list: https://launchpad.net/~openerp-dev-gtk Post to : openerp-dev-gtk@lists.launchpad.net Unsubscribe : https://launchpad.net/~openerp-dev-gtk More help : https://help.launchpad.net/ListHelp