[FIX]google_drive,google_base_account: back to httpllib
bzr revid: dle@openerp.com-20130626170035-rd4rzil801vbzxro
This commit is contained in:
parent
fab8c0682f
commit
1d85a0648c
|
@ -22,8 +22,8 @@
|
||||||
from openerp.osv import osv
|
from openerp.osv import osv
|
||||||
from openerp import SUPERUSER_ID
|
from openerp import SUPERUSER_ID
|
||||||
|
|
||||||
|
from httplib2 import Http
|
||||||
import urllib
|
import urllib
|
||||||
import urllib2
|
|
||||||
import simplejson
|
import simplejson
|
||||||
|
|
||||||
|
|
||||||
|
@ -38,14 +38,10 @@ class base_config_settings(osv.osv):
|
||||||
redirect_uri = ir_config.get_param(cr, SUPERUSER_ID, 'google_redirect_uri')
|
redirect_uri = ir_config.get_param(cr, SUPERUSER_ID, 'google_redirect_uri')
|
||||||
|
|
||||||
#Get the Refresh Token From Google And store it in ir.config_parameter
|
#Get the Refresh Token From Google And store it in ir.config_parameter
|
||||||
data = {
|
headers = {"Content-type": "application/x-www-form-urlencoded"}
|
||||||
'code': authorization_code,
|
data = dict(code=authorization_code, client_id=client_id, client_secret=client_secret, redirect_uri=redirect_uri, grant_type="authorization_code")
|
||||||
'client_id': client_id,
|
data = urllib.urlencode(data)
|
||||||
'client_secret': client_secret,
|
resp, content = Http().request("https://accounts.google.com/o/oauth2/token", "POST", data, headers)
|
||||||
'redirect_uri': redirect_uri,
|
|
||||||
'grant_type': "authorization_code",
|
|
||||||
}
|
|
||||||
resp, content = urllib2.urlopen("https://accounts.google.com/o/oauth2/token", urllib.urlencode(data))
|
|
||||||
content = simplejson.loads(content)
|
content = simplejson.loads(content)
|
||||||
if 'refresh_token' in content.keys():
|
if 'refresh_token' in content.keys():
|
||||||
ir_config.set_param(cr, uid, 'google_%s_refresh_token' % service, content['refresh_token'])
|
ir_config.set_param(cr, uid, 'google_%s_refresh_token' % service, content['refresh_token'])
|
||||||
|
|
|
@ -23,8 +23,8 @@ from openerp import SUPERUSER_ID
|
||||||
from openerp.osv import fields, osv
|
from openerp.osv import fields, osv
|
||||||
from openerp.tools.translate import _
|
from openerp.tools.translate import _
|
||||||
|
|
||||||
|
from httplib2 import Http
|
||||||
import urllib
|
import urllib
|
||||||
import urllib2
|
|
||||||
import json
|
import json
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ class config(osv.osv):
|
||||||
filter_name = config.filter_id and config.filter_id.name or False
|
filter_name = config.filter_id and config.filter_id.name or False
|
||||||
record = self.pool.get(model.model).read(cr, uid, res_id, [], context=context)
|
record = self.pool.get(model.model).read(cr, uid, res_id, [], context=context)
|
||||||
record.update({'model': model.name, 'filter': filter_name})
|
record.update({'model': model.name, 'filter': filter_name})
|
||||||
name_gdocs = config.name_template or "%(name)s_%(model)s_%(filter)s_gdrive"
|
name_gdocs = config.name_template
|
||||||
try:
|
try:
|
||||||
name_gdocs = name_gdocs % record
|
name_gdocs = name_gdocs % record
|
||||||
except:
|
except:
|
||||||
|
@ -65,26 +65,28 @@ class config(osv.osv):
|
||||||
google_web_base_url = ir_config.get_param(cr, SUPERUSER_ID, 'web.base.url')
|
google_web_base_url = ir_config.get_param(cr, SUPERUSER_ID, 'web.base.url')
|
||||||
|
|
||||||
#For Getting New Access Token With help of old Refresh Token
|
#For Getting New Access Token With help of old Refresh Token
|
||||||
|
headers = {"Content-type": "application/x-www-form-urlencoded"}
|
||||||
data = dict(client_id=google_drive_client_id,
|
data = dict(client_id=google_drive_client_id,
|
||||||
refresh_token=google_drive_refresh_token,
|
refresh_token=google_drive_refresh_token,
|
||||||
client_secret=google_drive_client_secret,
|
client_secret=google_drive_client_secret,
|
||||||
grant_type="refresh_token")
|
grant_type="refresh_token")
|
||||||
|
|
||||||
data = urllib.urlencode(data)
|
data = urllib.urlencode(data)
|
||||||
content = urllib2.urlopen("https://accounts.google.com/o/oauth2/token", data).read()
|
resp, content = Http().request("https://accounts.google.com/o/oauth2/token", "POST", data, headers)
|
||||||
content = json.loads(content)
|
content = json.loads(content)
|
||||||
|
|
||||||
# Copy template in to drive with help of new access token
|
# Copy template in to drive with help of new access token
|
||||||
if 'access_token' in content:
|
if 'access_token' in content:
|
||||||
request_url = "https://www.googleapis.com/drive/v2/files/%s?fields=parents/id&access_token=%s" % (template_id, content['access_token'])
|
request_url = "https://www.googleapis.com/drive/v2/files/%s?fields=parents/id&access_token=%s" % (template_id, content['access_token'])
|
||||||
parents = urllib2.urlopen(request_url).read()
|
resp, parents = Http().request(request_url, "GET")
|
||||||
parents_dict = json.loads(parents)
|
parents_dict = json.loads(parents)
|
||||||
|
|
||||||
record_url = "Click on link to open Record in OpenERP\n %s/?db=%s#id=%s&model=%s" % (google_web_base_url, cr.dbname, res_id, res_model)
|
record_url = "Click on link to open Record in OpenERP\n %s/?db=%s#id=%s&model=%s" % (google_web_base_url, cr.dbname, res_id, res_model)
|
||||||
data = {"title": name_gdocs, "description": record_url, "parents": parents_dict['parents']}
|
data = {"title": name_gdocs, "description": record_url, "parents": parents_dict['parents']}
|
||||||
request_url = "https://www.googleapis.com/drive/v2/files/%s/copy?access_token=%s" % (template_id, content['access_token'])
|
request_url = "https://www.googleapis.com/drive/v2/files/%s/copy?access_token=%s" % (template_id, content['access_token'])
|
||||||
|
headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
|
||||||
data_json = json.dumps(data)
|
data_json = json.dumps(data)
|
||||||
req = urllib2.Request(request_url, data_json, {'Content-Type': 'application/json', 'Content-Length': len(data_json)})
|
resp, content = Http().request(request_url, "POST", data_json, headers)
|
||||||
content = urllib2.urlopen(req).read()
|
|
||||||
content = json.loads(content)
|
content = json.loads(content)
|
||||||
res = False
|
res = False
|
||||||
if 'alternateLink' in content.keys():
|
if 'alternateLink' in content.keys():
|
||||||
|
@ -166,7 +168,7 @@ class config(osv.osv):
|
||||||
return res
|
return res
|
||||||
|
|
||||||
_defaults = {
|
_defaults = {
|
||||||
'name_template': '%(name)s_%(model)s_%(filter)s_gdrive',
|
'name_template': 'Document %(name)s',
|
||||||
}
|
}
|
||||||
|
|
||||||
def _check_model_id(self, cr, uid, ids, context=None):
|
def _check_model_id(self, cr, uid, ids, context=None):
|
||||||
|
|
|
@ -12,11 +12,11 @@
|
||||||
|
|
||||||
<!-- template demo -->
|
<!-- template demo -->
|
||||||
<record id="template_partner" model="google.drive.config">
|
<record id="template_partner" model="google.drive.config">
|
||||||
<field name="name">Customer Doc</field>
|
<field name="name">Partner Review</field>
|
||||||
<field name="model_id" ref="base.model_res_partner"/>
|
<field name="model_id" ref="base.model_res_partner"/>
|
||||||
<field name="filter_id" ref="filter_partner"/>
|
<field name="filter_id" ref="filter_partner"/>
|
||||||
<field name="google_drive_template_url">https://docs.google.com/spreadsheet/ccc?key=0Ah2qnrLAoZmUdGRvdVdmS1VoSDctWk1kd18taGZ4ckE#gid=0</field>
|
<field name="google_drive_template_url">https://docs.google.com/spreadsheet/ccc?key=0Ah2qnrLAoZmUdGRvdVdmS1VoSDctWk1kd18taGZ4ckE#gid=0</field>
|
||||||
<field name="name_template">%(name)s_%(model)s_%(filter)s_gdrive</field>
|
<field name="name_template">Partner Review %(name)s</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
</data>
|
</data>
|
||||||
|
|
Loading…
Reference in New Issue