[IMP] add oauth
bzr revid: mva@openerp.com-20120320160320-tykxuosgpq1r28ag
This commit is contained in:
parent
9d5db695ee
commit
f77cecb90c
|
@ -24,6 +24,9 @@ try:
|
|||
import gdata.docs.client
|
||||
from gdata.client import RequestError
|
||||
from gdata.docs.service import DOCUMENT_LABEL
|
||||
import gdata.auth
|
||||
import gdata.docs.service
|
||||
import webbrowser
|
||||
except ImportError:
|
||||
raise osv.except_osv(_('Google Docs Error!'), _('Please install gdata-python-client from http://code.google.com/p/gdata-python-client/downloads/list'))
|
||||
|
||||
|
@ -56,11 +59,15 @@ class google_docs_ir_attachment(osv.osv):
|
|||
'''
|
||||
|
||||
# authenticate
|
||||
|
||||
'''
|
||||
client = self._auth(cr, uid)
|
||||
if client == False:
|
||||
return False #return an error
|
||||
|
||||
|
||||
return False
|
||||
'''
|
||||
client = self.pool.get('google.oauth')
|
||||
client.login(cr,uid,ids,context=context)
|
||||
|
||||
# create the document in google docs
|
||||
if type_doc=='slide':
|
||||
local_resource = gdata.docs.data.Resource(gdata.docs.data.PRESENTATION_LABEL)
|
||||
|
@ -68,8 +75,9 @@ class google_docs_ir_attachment(osv.osv):
|
|||
local_resource = gdata.docs.data.Resource(gdata.docs.data.SPREADSHEET_LABEL)
|
||||
else:
|
||||
local_resource = gdata.docs.data.Resource(gdata.docs.data.DOCUMENT_LABEL)
|
||||
|
||||
gdocs_resource = client.post(entry=local_resource, uri='https://docs.google.com/feeds/default/private/full/')
|
||||
|
||||
#create a new doc in Google Docs
|
||||
gdocs_resource = client.Post(entry=local_resource, uri='https://docs.google.com/feeds/default/private/full/')
|
||||
|
||||
# register into the db
|
||||
self.create(cr, uid, {
|
||||
|
@ -117,14 +125,13 @@ class google_docs(osv.osv):
|
|||
return -1
|
||||
|
||||
|
||||
|
||||
class config(osv.osv):
|
||||
_name = 'google.docs.config'
|
||||
_description = "Google Docs templates config"
|
||||
|
||||
_columns = {
|
||||
'context_model_id': fields.many2one('ir.model', 'Model'),
|
||||
'context_gdocs_resource_id': fields.char('Google resource ID', size=64),
|
||||
'context_gdocs_resource_id': fields.char('Google resource ID', size=64,help='This is the id of the template document you kind find it in the URL'),
|
||||
'context_name_template': fields.char('GDoc name template ', size=64, help='This is the name which appears on google side'),
|
||||
'context_name': fields.char('Name', size=64, help='This is the attachment\'s name. As well, it appears on the panel.'),
|
||||
'context_multiple': fields.boolean('Multiple documents')
|
||||
|
@ -135,16 +142,35 @@ class config(osv.osv):
|
|||
'context_name': 'pr_%(name)',
|
||||
'context_multiple': False,
|
||||
}
|
||||
def has_config_set(self, cr, uid, model,context=None):
|
||||
print model
|
||||
import pdb
|
||||
pdb.set_trace()
|
||||
|
||||
def get_config(self, cr, uid, model):
|
||||
domain = [('context_model_id', '=', model)]
|
||||
if self.search_count(cr, uid, domain) != 0:
|
||||
return False
|
||||
else:
|
||||
return self.search(cr, uid, domain)
|
||||
|
||||
config()
|
||||
|
||||
|
||||
|
||||
class oauth (osv.osv):
|
||||
_name = 'google.oauth'
|
||||
def login(self,cr,uid,ids,context=None):
|
||||
consumer_key = '751376579939.apps.googleusercontent.com'
|
||||
consumer_secret = '_KGpgyO8DZIseyG3N-j-h8gN'
|
||||
gd_client = gdata.docs.service.DocsService()
|
||||
#Set OAuth input parameters
|
||||
gd_client.SetOAuthInputParameters(gdata.auth.OAuthSignatureMethod.HMAC_SHA1,consumer_key, consumer_secret=consumer_secret)
|
||||
#Fetch OAuth Request token
|
||||
request_token = gd_client.FetchOAuthRequestToken()
|
||||
#Set the fetched OAuth token
|
||||
gd_client.SetOAuthToken(request_token)
|
||||
#Generate OAuth authorization URL
|
||||
auth_url = gd_client.GenerateOAuthAuthorizationURL()
|
||||
webbrowser.open(auth_url)
|
||||
print gd_client.SetOAuthToken(request_token)
|
||||
consumer_key = raw_input('Please enter consumer key: ')
|
||||
|
||||
#Upgrade to an OAuth access token
|
||||
gd_client.UpgradeToOAuthAccessToken()
|
||||
#Access Token
|
||||
gd_client.token_store.find_token(request_token.scopes[0])
|
||||
|
|
|
@ -29,8 +29,6 @@
|
|||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
|
||||
<record model='ir.actions.act_window' id='action_google_docs_users_config'>
|
||||
<field name='name'>Models configuration</field>
|
||||
<field name='res_model'>google.docs.config</field>
|
||||
|
|
|
@ -12,7 +12,6 @@ openerp.google_docs = function(instance, session) {
|
|||
// if the configuration isn't set, the buttons should be hidden.
|
||||
if (r==false) {
|
||||
$('.oe_google_docs_text_button').css('display', 'none');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,14 +5,13 @@
|
|||
<t t-extend="FormView.sidebar.attachments">
|
||||
<t t-jquery="div.oe-binary-file-set" t-operation="append">
|
||||
<button class="oe_google_docs_text_button" type="button">
|
||||
<img src="/web/static/src/img/throbber.gif" width="16" height="16" style="display: none"/>
|
||||
<span>Add GDoc - text</span>
|
||||
<!--<img src="/web/static/src/img/throbber.gif" width="16" height="16"/>-->
|
||||
<span>Add A Goole Docs</span>
|
||||
</button>
|
||||
<button class="oe_google_docs_spreadsheet_button" type="button">
|
||||
<!--<button class="oe_google_docs_spreadsheet_button" type="button">
|
||||
<img src="/web/static/src/img/throbber.gif" width="16" height="16" style="display: none"/>
|
||||
<span>Add GDoc - spreadsheet</span>
|
||||
</button>
|
||||
<!--
|
||||
<button class="oe_google_docs_slide_button" type="button">
|
||||
<img src="/web/static/src/img/throbber.gif" width="16" height="16" style="display: none"/>
|
||||
<span>Add GDoc - presentation</span>
|
||||
|
|
Loading…
Reference in New Issue