1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as
9 # published by the Free Software Foundation, either version 3 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ##############################################################################
24 from urlparse import urlparse, urlunparse
27 from openerp.osv import fields, osv
29 class Binary(openerp.addons.web.http.Controller):
30 _cp_path = "/web_linkedin/binary"
32 @openerp.addons.web.http.jsonrequest
33 def url2binary(self, req, url):
34 """Used exclusively to load images from LinkedIn profiles, must not be used for anything else."""
35 req.session.assert_valid(force=True)
36 _scheme, _netloc, path, params, query, fragment = urlparse(url)
37 # media.linkedin.com is the master domain for LinkedIn media (replicated to CDNs),
38 # so forcing it should always work and prevents abusing this method to load arbitrary URLs
39 url = urlunparse(('http', 'media.linkedin.com', path, params, query, fragment))
40 bfile = urllib2.urlopen(url)
41 return base64.b64encode(bfile.read())
43 class web_linkedin_settings(osv.osv_memory):
44 _inherit = 'sale.config.settings'
46 'api_key': fields.char(string="API Key", size=50),
47 'server_domain': fields.char(size=100),
50 def get_default_linkedin(self, cr, uid, fields, context=None):
51 key = self.pool.get("ir.config_parameter").get_param(cr, uid, "web.linkedin.apikey") or ""
52 dom = self.pool.get('ir.config_parameter').get_param(cr, uid, 'web.base.url')
53 return {'api_key': key, 'server_domain': dom,}
55 def set_linkedin(self, cr, uid, ids, context=None):
56 key = self.browse(cr, uid, ids[0], context)["api_key"] or ""
57 self.pool.get("ir.config_parameter").set_param(cr, uid, "web.linkedin.apikey", key)