summaryrefslogtreecommitdiff
path: root/addons/google_docs/google_docs.py
diff options
context:
space:
mode:
authorMVA <mva@openerp.com>2012-03-19 11:31:32 +0100
committerMVA <mva@openerp.com>2012-03-19 11:31:32 +0100
commit9d5db695ee3e1cfc1f0d306bccf117640a14927b (patch)
tree34fd81e18758843760a9c1f4c3304de21850a14e /addons/google_docs/google_docs.py
parentebb97da4d16ffdbf74091bc6742f1f175ac0142b (diff)
[REF] correct the code and change the view files
bzr revid: mva@openerp.com-20120319103132-av7c09avg4p0xgt3
Diffstat (limited to 'addons/google_docs/google_docs.py')
-rw-r--r--addons/google_docs/google_docs.py51
1 files changed, 26 insertions, 25 deletions
diff --git a/addons/google_docs/google_docs.py b/addons/google_docs/google_docs.py
index e822bb304bf..d37f28eb349 100644
--- a/addons/google_docs/google_docs.py
+++ b/addons/google_docs/google_docs.py
@@ -30,22 +30,22 @@ except ImportError:
class google_docs_ir_attachment(osv.osv):
_inherit = 'ir.attachment'
- def _auth(self, cr, uid):
+ def _auth(self, cr, uid,context=None):
# check google_base_account
users_obj = self.pool.get('res.users')
user = users_obj.browse(cr, uid, [uid])[0]
- if not user.gmail_user or not user.gmail_password:
+ if not user.gmail_user or not user.gmail_password:
return False
# login
client = gdata.docs.client.DocsClient(source='openerp.com')
client.ssl = True
client.http_client.debug = False
- client.ClientLogin(user.gmail_user, user.gmail_password, client.source, service='writely')
+ client.ClientLogin(user.gmail_user, user.gmail_password, client.source, service='writely') #authentification in a gmail account
return client
- def create_empty_google_doc(self, cr, uid, model, ids, type_doc):
+ def create_empty_google_doc(self, cr, uid, model, ids, type_doc,context=None):
'''Associate a copy of the gdoc identified by 'gdocs_res_id' to the current entity.
@param cr: the current row from the database cursor.
@param uid: the current user ID, for security checks.
@@ -54,12 +54,13 @@ class google_docs_ir_attachment(osv.osv):
@return the document object.
@return False if the google_base_account hasn't been configured yet.
'''
-
+
# authenticate
client = self._auth(cr, uid)
if client == False:
- return False
-
+ return False #return an error
+
+
# create the document in google docs
if type_doc=='slide':
local_resource = gdata.docs.data.Resource(gdata.docs.data.PRESENTATION_LABEL)
@@ -67,6 +68,7 @@ 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/')
# register into the db
@@ -76,30 +78,28 @@ class google_docs_ir_attachment(osv.osv):
'type': 'url',
'name': 'new_foo %s' % (type_doc,) , # TODO pending from the working config
'url': gdocs_resource.get_alternate_link().href
- })
-
+ },context=context)
+
+
return gdocs_resource
- def copy_gdoc(self, cr, uid, model, ids):
- if context is None:
- context={}
-
+ def copy_gdoc(self, cr, uid, model, ids,context=None):
client = self._auth(cr, uid)
if client == False:
return False
-
# fetch and copy the original document
original_resource = client.get_resource_by_id(gdocs_resource_id)
copy_resource = client.copy_resource(entry=original_resource)
-
+
# register into the db
self.create(cr, uid, {
'res_model': model,
'res_id': ids[0],
'type': 'url',
- 'name': 'copy_foo %s' (type_doc,) , # TODO pending from the working config
+ 'name': 'file_name',
+ 'name': 'copy_foo %s' (type_doc,) , #TODO pending from the working config
'url': copy_resource.get_alternate_link().href
- })
+ },context=context)
return copy_resource
@@ -107,19 +107,16 @@ class google_docs(osv.osv):
_name = 'google.docs'
def doc_get(self, cr, uid, model, id, type_doc):
- google_docs_config_ref = self.pool.get('res.users')
ir_attachment_ref = self.pool.get('ir.attachment')
- google_docs_config = google_docs_config_ref.search(cr, uid, [('context_model_id', '=', model)])
+ google_docs_config = self.pool.get('google.docs.config').search(cr, uid, [('context_model_id', '=', model)])
- if not google_docs_config:
- google_document = ir_attachment_ref.create_empty_google_doc(cr, uid, model, id, type_doc)
- else:
+ if google_docs_config:
google_document = ir_attachment_ref.copy_gdoc(cr, uid, model, id)
+ else:
+ google_document = ir_attachment_ref.create_empty_google_doc(cr, uid, model, id, type_doc)
+ return -1
- print google_docs_config
- if not google_docs_config:
- return -1
class config(osv.osv):
_name = 'google.docs.config'
@@ -138,6 +135,10 @@ 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)]