[IMP] show company logo in chrome
bzr revid: chs@openerp.com-20121211111824-dj2ienybj2rxwhjj
This commit is contained in:
parent
b83c11d61a
commit
060ef93268
|
@ -1,5 +1,6 @@
|
||||||
import http
|
import http
|
||||||
import controllers
|
import controllers
|
||||||
import cli
|
import cli
|
||||||
|
import res_company
|
||||||
|
|
||||||
wsgi_postload = http.wsgi_postload
|
wsgi_postload = http.wsgi_postload
|
||||||
|
|
|
@ -28,11 +28,13 @@ except ImportError:
|
||||||
xlwt = None
|
xlwt = None
|
||||||
|
|
||||||
import openerp
|
import openerp
|
||||||
|
import openerp.modules.registry
|
||||||
from openerp.tools.translate import _
|
from openerp.tools.translate import _
|
||||||
|
|
||||||
from .. import http
|
from .. import http
|
||||||
openerpweb = http
|
openerpweb = http
|
||||||
|
|
||||||
|
_logger = logging.getLogger(__name__)
|
||||||
#----------------------------------------------------------
|
#----------------------------------------------------------
|
||||||
# OpenERP Web helpers
|
# OpenERP Web helpers
|
||||||
#----------------------------------------------------------
|
#----------------------------------------------------------
|
||||||
|
@ -169,7 +171,6 @@ def module_installed_bypass_session(dbname):
|
||||||
loadable = openerpweb.addons_manifest.keys()
|
loadable = openerpweb.addons_manifest.keys()
|
||||||
modules = {}
|
modules = {}
|
||||||
try:
|
try:
|
||||||
import openerp.modules.registry
|
|
||||||
registry = openerp.modules.registry.RegistryManager.get(dbname)
|
registry = openerp.modules.registry.RegistryManager.get(dbname)
|
||||||
with registry.cursor() as cr:
|
with registry.cursor() as cr:
|
||||||
m = registry.get('ir.module.module')
|
m = registry.get('ir.module.module')
|
||||||
|
@ -1202,9 +1203,10 @@ class Binary(openerpweb.Controller):
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
return req.make_response(image_data, headers)
|
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']
|
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
|
@openerpweb.httprequest
|
||||||
def saveas(self, req, model, field, id=None, filename_field=None, **kw):
|
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]}
|
args = {'erorr':e.faultCode.split('--')[1],'title':e.faultCode.split('--')[0]}
|
||||||
return out % (simplejson.dumps(callback), simplejson.dumps(args))
|
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):
|
class Action(openerpweb.Controller):
|
||||||
_cp_path = "/web/action"
|
_cp_path = "/web/action"
|
||||||
|
|
||||||
|
|
|
@ -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),
|
||||||
|
}),
|
||||||
|
}
|
|
@ -1134,12 +1134,8 @@
|
||||||
width: 220px;
|
width: 220px;
|
||||||
display: block;
|
display: block;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
height: 70px;
|
|
||||||
line-height: 70px;
|
|
||||||
}
|
}
|
||||||
.openerp a.oe_logo img {
|
.openerp a.oe_logo img {
|
||||||
height: 40px;
|
|
||||||
width: 157px;
|
|
||||||
margin: 14px 0;
|
margin: 14px 0;
|
||||||
border: 0;
|
border: 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -927,11 +927,7 @@ $sheet-padding: 16px
|
||||||
width: 220px
|
width: 220px
|
||||||
display: block
|
display: block
|
||||||
text-align: center
|
text-align: center
|
||||||
height: 70px
|
|
||||||
line-height: 70px
|
|
||||||
img
|
img
|
||||||
height: 40px
|
|
||||||
width: 157px
|
|
||||||
margin: 14px 0
|
margin: 14px 0
|
||||||
border: 0
|
border: 0
|
||||||
.oe_footer
|
.oe_footer
|
||||||
|
|
|
@ -1172,6 +1172,7 @@ instance.web.WebClient = instance.web.Client.extend({
|
||||||
show_application: function() {
|
show_application: function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
self.toggle_bars(true);
|
self.toggle_bars(true);
|
||||||
|
self.update_logo();
|
||||||
self.menu = new instance.web.Menu(self);
|
self.menu = new instance.web.Menu(self);
|
||||||
self.menu.replace(this.$el.find('.oe_menu_placeholder'));
|
self.menu.replace(this.$el.find('.oe_menu_placeholder'));
|
||||||
self.menu.on('menu_click', this, this.on_menu_action);
|
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.set_title();
|
||||||
self.check_timezone();
|
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() {
|
check_timezone: function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
return new instance.web.Model('res.users').call('read', [[this.session.uid], ['tz_offset']]).then(function(result) {
|
return new instance.web.Model('res.users').call('read', [[this.session.uid], ['tz_offset']]).then(function(result) {
|
||||||
|
|
|
@ -439,7 +439,7 @@
|
||||||
<tr>
|
<tr>
|
||||||
<td class="oe_leftbar" valign="top">
|
<td class="oe_leftbar" valign="top">
|
||||||
<t t-set="debug" t-value="__debug__ ? '&debug' : ''"/>
|
<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_secondary_menus_container"/>
|
||||||
<div class="oe_footer">
|
<div class="oe_footer">
|
||||||
Powered by <a href="http://www.openerp.com" target="_blank"><span>OpenERP</span></a>
|
Powered by <a href="http://www.openerp.com" target="_blank"><span>OpenERP</span></a>
|
||||||
|
|
Loading…
Reference in New Issue