[Fix]replace callenabled for on_button_cancel
[odoo/odoo.git] / addons / web_linkedin / web_linkedin.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
6 #
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.
11 #
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.
16 #
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/>.
19 #
20 ##############################################################################
21
22 try:
23     # embedded
24     import openerp.addons.web.common.http as openerpweb
25 except ImportError:
26     # standalone
27     import web.common.http as openerpweb
28
29 import base64
30 import urllib2
31 from osv import osv, fields
32
33 class Binary(openerpweb.Controller):
34     _cp_path = "/web_linkedin/binary"
35
36     @openerpweb.jsonrequest
37     def url2binary(self, req,url):
38         bfile = urllib2.urlopen(url)
39         return base64.b64encode(bfile.read())
40     
41 class web_linkedin_settings(osv.osv_memory):
42     _inherit = 'sale.config.settings'
43     _columns = {
44         'api_key': fields.char(string="API Key", size=50),
45         'server_domain': fields.char(size=100),
46     }
47     
48     def get_default_linkedin(self, cr, uid, fields, context=None):
49         key = self.pool.get("ir.config_parameter").get_param(cr, uid, "web.linkedin.apikey") or ""
50         dom = self.pool.get('ir.config_parameter').get_param(cr, uid, 'web.base.url')
51         return {'api_key': key, 'server_domain': dom,}
52     
53     def set_linkedin(self, cr, uid, ids, context=None):
54         key = self.browse(cr, uid, ids[0], context)["api_key"] or ""
55         self.pool.get("ir.config_parameter").set_param(cr, uid, "web.linkedin.apikey", key)
56