From fefd25861a820d489feeb85f665c79d88b017c24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20L=C3=B3pez=20L=C3=B3pez=20=28OpenERP=29?= Date: Fri, 24 Feb 2012 11:52:15 +0100 Subject: [IMP] new module google_docs bzr revid: rlo@openerp.com-20120224105215-clev3ip7n8zhb3kt --- addons/google_docs/google_docs.py | 119 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 addons/google_docs/google_docs.py (limited to 'addons/google_docs/google_docs.py') diff --git a/addons/google_docs/google_docs.py b/addons/google_docs/google_docs.py new file mode 100644 index 00000000000..a2693ac95a7 --- /dev/null +++ b/addons/google_docs/google_docs.py @@ -0,0 +1,119 @@ +from osv import osv, fields +import gdata.docs.data +import gdata.docs.client +from gdata.client import RequestError + +class google_docs(osv.osv): + _name = 'google.docs' + + _table = 'google_docs_templates' + _columns = { + 'id': fields.integer('ID', readonly=True), + 'model': fields.many2one('ir.model', 'Model'), + 'gdocs_res_id': fields.char('Google resource ID', size=64, translate=False) + } + + edit_url_template = 'https://docs.google.com/Edit?docid=%s' + prefix_gdoc_id_res = 'document:' + + def copy_gdoc(self, cr, uid, model, 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. + @param model: the current model name. + @param context: a standard dictionary for contextual values. + @return the url of the copy itself. + @return -1 if the template hasn't been assigned yet. + @return -2 if the google_base_account hasn't been configured yet.''' + + if context==None: + context={} + + # check template for the current model + model_obj = self.pool.get(model) + res_gdocs_obj = self.pool.get('google.docs') + domain = [('model' , '=', model_obj)] + gdoc = res_gdocs_obj.search(cr,uid,domain,context=context) + if not gdoc: + return -1 + + # 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: + return -2 + + # copy the document + 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') + resource = client.get_resource_by_id(gdoc.gdocs_res_id) + copied_resource = client.copy_resource(entry=resource, title=resource.title.text + ' (generated from OpenERP)') + + return self.edit_url_template % (copied_resource.resource_id.text,) + + def get_documents_list(self, cr, uid, context=None): + '''Return the list of google documents available at the user's account. + @param cr: the current row from the database cursor. + @param uid: the current user ID, for security checks. + @param context: a standard dictionary for contextual values. + @return a list with information about the documents in form of tuples (document_name, document_resource_id). + @return -2 if the google_base_account hasn't been configured yet.''' + + if context == None: + context = {} + + # 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: + return -2 + + # get the documents list + 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') + + return map(lambda doc: (doc.title.text, doc.resource_id.text[len(prefix_gdoc_id_res):]), filter(lambda r: r.resource_id.text.startswith('document:'), client.get_all_resources())) + + + def set_model_document_template(self, cr, uid, model, resource_id, context=None): + '''Set the default document template for the specified model. This template doesn't have to be a google documents template itself, but just a document. + @param cr: current row for the database cursor. + @param uid: the current user ID, for security checks. + @param model: the current model name. + @param resource_id: resource_id associated to the chosen document. + @param context: a standard dictionary for contextual values. + @return 0 on successful execution. + @return -2 if the google_base_account hasn't been configured yet. + @retrurn -3 if the given resource_id doesn't exist in the user's google docs account. + ''' + + if context == None: + context = {} + + # 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: + return -2 + + # check resource_id + 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') + try: + client.get_resource_by_id(resource_id) + except RequestError: + return -3 + + # set the model document template + model_template_id = self.create(cr, uid, + { 'model': self.pool.get(model), + 'gdocs_res_id': resource_id + }) + + return 0 -- cgit v1.2.3 From e4a58bf7c57a8c00a8c7451372bed96704f522d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20L=C3=B3pez=20L=C3=B3pez=20=28OpenERP=29?= Date: Fri, 24 Feb 2012 12:03:09 +0100 Subject: [FIX] bzr revid: rlo@openerp.com-20120224110309-0hdmfu8vo918906q --- addons/google_docs/google_docs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'addons/google_docs/google_docs.py') diff --git a/addons/google_docs/google_docs.py b/addons/google_docs/google_docs.py index a2693ac95a7..957fcbf0871 100644 --- a/addons/google_docs/google_docs.py +++ b/addons/google_docs/google_docs.py @@ -88,7 +88,7 @@ class google_docs(osv.osv): @param context: a standard dictionary for contextual values. @return 0 on successful execution. @return -2 if the google_base_account hasn't been configured yet. - @retrurn -3 if the given resource_id doesn't exist in the user's google docs account. + @return -3 if the given resource_id doesn't exist in the user's google docs account. ''' if context == None: -- cgit v1.2.3 From 9d28250005d879408ebbd73a05c8be40ee1a8105 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20L=C3=B3pez=20L=C3=B3pez=20=28OpenERP=29?= Date: Fri, 24 Feb 2012 14:30:15 +0100 Subject: [imp] bzr revid: rlo@openerp.com-20120224133015-2vt3gnkknnh2vrjd --- addons/google_docs/google_docs.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'addons/google_docs/google_docs.py') diff --git a/addons/google_docs/google_docs.py b/addons/google_docs/google_docs.py index 957fcbf0871..46db3eb4448 100644 --- a/addons/google_docs/google_docs.py +++ b/addons/google_docs/google_docs.py @@ -2,6 +2,7 @@ from osv import osv, fields import gdata.docs.data import gdata.docs.client from gdata.client import RequestError +from gdata.docs.service import DOCUMENT_LABEL class google_docs(osv.osv): _name = 'google.docs' @@ -13,14 +14,16 @@ class google_docs(osv.osv): 'gdocs_res_id': fields.char('Google resource ID', size=64, translate=False) } + name_template = 'Sales order %s %s' edit_url_template = 'https://docs.google.com/Edit?docid=%s' - prefix_gdoc_id_res = 'document:' + prefix_gdoc_id_res = DOCUMENT_LABEL + ':' - def copy_gdoc(self, cr, uid, model, context=None): + def copy_gdoc(self, cr, uid, model, folder=None, 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. @param model: the current model name. + @param folder: folder in which to store the copy. @param context: a standard dictionary for contextual values. @return the url of the copy itself. @return -1 if the template hasn't been assigned yet. @@ -49,7 +52,7 @@ class google_docs(osv.osv): client.http_client.debug = False client.ClientLogin(user.gmail_user, user.gmail_password, client.source, service='writely') resource = client.get_resource_by_id(gdoc.gdocs_res_id) - copied_resource = client.copy_resource(entry=resource, title=resource.title.text + ' (generated from OpenERP)') + copied_resource = client.copy_resource(entry=resource, title= self.name_template % (, model)) return self.edit_url_template % (copied_resource.resource_id.text,) @@ -117,3 +120,10 @@ class google_docs(osv.osv): }) return 0 + + +class google_docs_folder(osv.osv): + _name = 'google.docs.folder' + _columns = { + 'res_id': fields.char('GDocs resource id', size=64, translate=False), + } -- cgit v1.2.3 From 9eaa5de2aca09c44976d5472dbb66565038be494 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20L=C3=B3pez=20L=C3=B3pez=20=28OpenERP=29?= Date: Fri, 24 Feb 2012 14:52:28 +0100 Subject: [fix] bzr revid: rlo@openerp.com-20120224135228-rurois3a83l50lu1 --- addons/google_docs/google_docs.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'addons/google_docs/google_docs.py') diff --git a/addons/google_docs/google_docs.py b/addons/google_docs/google_docs.py index 46db3eb4448..538511b51c2 100644 --- a/addons/google_docs/google_docs.py +++ b/addons/google_docs/google_docs.py @@ -12,9 +12,9 @@ class google_docs(osv.osv): 'id': fields.integer('ID', readonly=True), 'model': fields.many2one('ir.model', 'Model'), 'gdocs_res_id': fields.char('Google resource ID', size=64, translate=False) + 'name_template': fields.char('Google resource ID', size=64, translate=False) } - name_template = 'Sales order %s %s' edit_url_template = 'https://docs.google.com/Edit?docid=%s' prefix_gdoc_id_res = DOCUMENT_LABEL + ':' @@ -32,6 +32,15 @@ class google_docs(osv.osv): if context==None: context={} + template_vars = { + 'db' : cr.dbname, + 'model' : model, + 'id' : id, + 'salt' : salt, + 'name' : '', + } + name_template = 'Sales order %s %s' + # check template for the current model model_obj = self.pool.get(model) res_gdocs_obj = self.pool.get('google.docs') -- cgit v1.2.3 From 2df3400a35696a0a95925edd1592c2467e9802a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20L=C3=B3pez=20L=C3=B3pez=20=28OpenERP=29?= Date: Fri, 24 Feb 2012 14:53:15 +0100 Subject: [fix] bzr revid: rlo@openerp.com-20120224135315-31phn9wvp1meth03 --- addons/google_docs/google_docs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'addons/google_docs/google_docs.py') diff --git a/addons/google_docs/google_docs.py b/addons/google_docs/google_docs.py index 538511b51c2..d4f48edb91a 100644 --- a/addons/google_docs/google_docs.py +++ b/addons/google_docs/google_docs.py @@ -12,7 +12,7 @@ class google_docs(osv.osv): 'id': fields.integer('ID', readonly=True), 'model': fields.many2one('ir.model', 'Model'), 'gdocs_res_id': fields.char('Google resource ID', size=64, translate=False) - 'name_template': fields.char('Google resource ID', size=64, translate=False) + 'name_template': fields.char('GDoc name template', size=64, translate=False) } edit_url_template = 'https://docs.google.com/Edit?docid=%s' -- cgit v1.2.3 From 33c3e277b6b496f8aa1c5a22c244390e29a6fba5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20L=C3=B3pez=20L=C3=B3pez=20=28OpenERP=29?= Date: Fri, 24 Feb 2012 14:54:58 +0100 Subject: [fix] bzr revid: rlo@openerp.com-20120224135458-2bz5k9fyyjymylye --- addons/google_docs/google_docs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'addons/google_docs/google_docs.py') diff --git a/addons/google_docs/google_docs.py b/addons/google_docs/google_docs.py index d4f48edb91a..0ad64124d04 100644 --- a/addons/google_docs/google_docs.py +++ b/addons/google_docs/google_docs.py @@ -88,7 +88,7 @@ class google_docs(osv.osv): client.http_client.debug = False client.ClientLogin(user.gmail_user, user.gmail_password, client.source, service='writely') - return map(lambda doc: (doc.title.text, doc.resource_id.text[len(prefix_gdoc_id_res):]), filter(lambda r: r.resource_id.text.startswith('document:'), client.get_all_resources())) + return map(lambda doc: (doc.title.text, doc.resource_id.text[len(prefix_gdoc_id_res):]), filter(lambda r: r.resource_id.text.startswith(prefix_gdoc_id_res), client.get_all_resources())) def set_model_document_template(self, cr, uid, model, resource_id, context=None): -- cgit v1.2.3 From d680f6c1a16d8f1415b78c8de674c32b6949aba3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20L=C3=B3pez=20L=C3=B3pez=20=28OpenERP=29?= Date: Fri, 24 Feb 2012 15:01:19 +0100 Subject: [fix] bzr revid: rlo@openerp.com-20120224140119-hoapkm5d13uietx1 --- addons/google_docs/google_docs.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'addons/google_docs/google_docs.py') diff --git a/addons/google_docs/google_docs.py b/addons/google_docs/google_docs.py index 0ad64124d04..718952fba34 100644 --- a/addons/google_docs/google_docs.py +++ b/addons/google_docs/google_docs.py @@ -27,19 +27,20 @@ class google_docs(osv.osv): @param context: a standard dictionary for contextual values. @return the url of the copy itself. @return -1 if the template hasn't been assigned yet. - @return -2 if the google_base_account hasn't been configured yet.''' + @return -2 if the google_base_account hasn't been configured yet. + ''' if context==None: context={} - template_vars = { + template_vars = { 'db' : cr.dbname, 'model' : model, 'id' : id, 'salt' : salt, 'name' : '', } - name_template = 'Sales order %s %s' + name_template = 'Sales order %s %s' # check template for the current model model_obj = self.pool.get(model) @@ -71,7 +72,8 @@ class google_docs(osv.osv): @param uid: the current user ID, for security checks. @param context: a standard dictionary for contextual values. @return a list with information about the documents in form of tuples (document_name, document_resource_id). - @return -2 if the google_base_account hasn't been configured yet.''' + @return -2 if the google_base_account hasn't been configured yet. + ''' if context == None: context = {} -- cgit v1.2.3 From 38291a99acc380b8f5e4f17736f06dfe28815267 Mon Sep 17 00:00:00 2001 From: Antony Lesuisse Date: Fri, 24 Feb 2012 15:39:23 +0100 Subject: commit bzr revid: al@openerp.com-20120224143923-pm9home907bxztqt --- addons/google_docs/google_docs.py | 56 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'addons/google_docs/google_docs.py') diff --git a/addons/google_docs/google_docs.py b/addons/google_docs/google_docs.py index 718952fba34..8a48de0b05c 100644 --- a/addons/google_docs/google_docs.py +++ b/addons/google_docs/google_docs.py @@ -4,6 +4,62 @@ import gdata.docs.client from gdata.client import RequestError from gdata.docs.service import DOCUMENT_LABEL +# _columns = { +# 'id': fields.integer('ID', readonly=True), +# 'model': fields.many2one('ir.model', 'Model'), +# 'multiple': fields.boolean('Multiple'), +# 'gdocs_res_id': fields.char('Google resource ID', size=64, translate=False) +# +# } +# +## edit_url_template = 'https://docs.google.com/Edit?docid=%s' +## prefix_gdoc_id_res = 'document:' +# +# def google_docs_get(self, cr, uid, model, id): +# attachment = self.search(cr, uid, [('res_model', '=', model), ('res_id', '=', id), ('type', '=', 'url'), ('url', 'like', 'https://docs.oogle.com')]) +# if attachment: +# return self.read(cr, uid, attachment)[0]['url'] +# else: +# url = self.pad_generate_url(cr, uid, model, id) +# self.create(cr, uid, { +# 'res_model' : model, +# 'res_id' : id, +# 'type' : 'url', +# 'name' : 'Pad', +# 'url' : url, +# }) +# return url +# +# def generate_name(self, cr, uid, model, id): +# template_vars = { +# 'db' : cr.dbname, +# 'model' : model, +# 'id' : id, +# 'salt' : salt, +# 'name' : self.pool.get(model).name_get(cr,uid,[id])[0], +# } +# return pad_url_template % template_vars +# +# +# def button_add_google_docs_google_docs_add_doc(self, cr, uid, model, id): +# #pad_url_template = self.pool.get('res.users').browse(cr,uid,[uid])[0].company_id.pad_url_template +# #s = string.ascii_uppercase + string.digits +# #salt = ''.join([s[random.randint(0, len(s) - 1)] for i in range(8)]) +# +# # i lookup in the table google_docs.templates to check the policy +# +# # if multiple: 1 +# +# # if i find a template i will duplicate the template +# +# # else empty 'word' text +# +# # else +# # if no document exists do like 1 -^ +# # else +# # jumpt to the existing document +# + class google_docs(osv.osv): _name = 'google.docs' -- cgit v1.2.3 From fd914eb2e3e09fec08733989e5c8456d4516194a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20L=C3=B3pez=20L=C3=B3pez=20=28OpenERP=29?= Date: Fri, 24 Feb 2012 16:29:20 +0100 Subject: [fix] bzr revid: rlo@openerp.com-20120224152920-vdi47f2k49kke2e0 --- addons/google_docs/google_docs.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'addons/google_docs/google_docs.py') diff --git a/addons/google_docs/google_docs.py b/addons/google_docs/google_docs.py index 8a48de0b05c..90edb15b104 100644 --- a/addons/google_docs/google_docs.py +++ b/addons/google_docs/google_docs.py @@ -67,7 +67,7 @@ class google_docs(osv.osv): _columns = { 'id': fields.integer('ID', readonly=True), 'model': fields.many2one('ir.model', 'Model'), - 'gdocs_res_id': fields.char('Google resource ID', size=64, translate=False) + 'gdocs_res_id': fields.char('Google resource ID', size=64, translate=False), 'name_template': fields.char('GDoc name template', size=64, translate=False) } @@ -96,7 +96,7 @@ class google_docs(osv.osv): 'salt' : salt, 'name' : '', } - name_template = 'Sales order %s %s' + name_template = 'Sales order %s' # check template for the current model model_obj = self.pool.get(model) @@ -118,7 +118,7 @@ class google_docs(osv.osv): client.http_client.debug = False client.ClientLogin(user.gmail_user, user.gmail_password, client.source, service='writely') resource = client.get_resource_by_id(gdoc.gdocs_res_id) - copied_resource = client.copy_resource(entry=resource, title= self.name_template % (, model)) + copied_resource = client.copy_resource(entry=resource, title= self.name_template % (model, )) return self.edit_url_template % (copied_resource.resource_id.text,) -- cgit v1.2.3 From 37ed7a1d9f1819fd39cbf0eb0679ae17e1afd91a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20L=C3=B3pez=20L=C3=B3pez=20=28OpenERP=29?= Date: Mon, 27 Feb 2012 13:38:34 +0100 Subject: [imp] view bzr revid: rlo@openerp.com-20120227123834-todar214ngca7pu0 --- addons/google_docs/google_docs.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'addons/google_docs/google_docs.py') diff --git a/addons/google_docs/google_docs.py b/addons/google_docs/google_docs.py index 90edb15b104..def1f3097e1 100644 --- a/addons/google_docs/google_docs.py +++ b/addons/google_docs/google_docs.py @@ -74,12 +74,11 @@ class google_docs(osv.osv): edit_url_template = 'https://docs.google.com/Edit?docid=%s' prefix_gdoc_id_res = DOCUMENT_LABEL + ':' - def copy_gdoc(self, cr, uid, model, folder=None, context=None): + def copy_gdoc(self, cr, uid, model, 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. @param model: the current model name. - @param folder: folder in which to store the copy. @param context: a standard dictionary for contextual values. @return the url of the copy itself. @return -1 if the template hasn't been assigned yet. -- cgit v1.2.3 From 95d9cb9f4ec264b0ee35fdc5bef9058d9cfdbe0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20L=C3=B3pez=20L=C3=B3pez=20=28OpenERP=29?= Date: Mon, 27 Feb 2012 14:54:25 +0100 Subject: [imp] view bzr revid: rlo@openerp.com-20120227135425-879tmcgw20dfy2a1 --- addons/google_docs/google_docs.py | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) (limited to 'addons/google_docs/google_docs.py') diff --git a/addons/google_docs/google_docs.py b/addons/google_docs/google_docs.py index def1f3097e1..59101ba5b09 100644 --- a/addons/google_docs/google_docs.py +++ b/addons/google_docs/google_docs.py @@ -70,7 +70,15 @@ class google_docs(osv.osv): 'gdocs_res_id': fields.char('Google resource ID', size=64, translate=False), 'name_template': fields.char('GDoc name template', size=64, translate=False) } + print ''' +######################################### + +GOOGLE DOCS + +######################################### + +''' edit_url_template = 'https://docs.google.com/Edit?docid=%s' prefix_gdoc_id_res = DOCUMENT_LABEL + ':' @@ -84,6 +92,15 @@ class google_docs(osv.osv): @return -1 if the template hasn't been assigned yet. @return -2 if the google_base_account hasn't been configured yet. ''' + print ''' + +######################################### + +google_docs.copy_gdoc() + +######################################### + +''' if context==None: context={} @@ -121,14 +138,15 @@ class google_docs(osv.osv): return self.edit_url_template % (copied_resource.resource_id.text,) +''' def get_documents_list(self, cr, uid, context=None): - '''Return the list of google documents available at the user's account. + ' ''Return the list of google documents available at the user's account. @param cr: the current row from the database cursor. @param uid: the current user ID, for security checks. @param context: a standard dictionary for contextual values. @return a list with information about the documents in form of tuples (document_name, document_resource_id). @return -2 if the google_base_account hasn't been configured yet. - ''' + '' ' if context == None: context = {} @@ -146,10 +164,11 @@ class google_docs(osv.osv): client.ClientLogin(user.gmail_user, user.gmail_password, client.source, service='writely') return map(lambda doc: (doc.title.text, doc.resource_id.text[len(prefix_gdoc_id_res):]), filter(lambda r: r.resource_id.text.startswith(prefix_gdoc_id_res), client.get_all_resources())) +''' - +''' def set_model_document_template(self, cr, uid, model, resource_id, context=None): - '''Set the default document template for the specified model. This template doesn't have to be a google documents template itself, but just a document. + '' 'Set the default document template for the specified model. This template doesn't have to be a google documents template itself, but just a document. @param cr: current row for the database cursor. @param uid: the current user ID, for security checks. @param model: the current model name. @@ -158,7 +177,7 @@ class google_docs(osv.osv): @return 0 on successful execution. @return -2 if the google_base_account hasn't been configured yet. @return -3 if the given resource_id doesn't exist in the user's google docs account. - ''' + ' '' if context == None: context = {} @@ -186,7 +205,7 @@ class google_docs(osv.osv): }) return 0 - +''' class google_docs_folder(osv.osv): _name = 'google.docs.folder' -- cgit v1.2.3 From 087c191730d611058b0303cf38d10989d868a7f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20L=C3=B3pez=20L=C3=B3pez=20=28OpenERP=29?= Date: Mon, 27 Feb 2012 14:57:51 +0100 Subject: [imp] view bzr revid: rlo@openerp.com-20120227135751-33nd5qduv2jp58cu --- addons/google_docs/google_docs.py | 56 --------------------------------------- 1 file changed, 56 deletions(-) (limited to 'addons/google_docs/google_docs.py') diff --git a/addons/google_docs/google_docs.py b/addons/google_docs/google_docs.py index 59101ba5b09..2f2c4919271 100644 --- a/addons/google_docs/google_docs.py +++ b/addons/google_docs/google_docs.py @@ -4,62 +4,6 @@ import gdata.docs.client from gdata.client import RequestError from gdata.docs.service import DOCUMENT_LABEL -# _columns = { -# 'id': fields.integer('ID', readonly=True), -# 'model': fields.many2one('ir.model', 'Model'), -# 'multiple': fields.boolean('Multiple'), -# 'gdocs_res_id': fields.char('Google resource ID', size=64, translate=False) -# -# } -# -## edit_url_template = 'https://docs.google.com/Edit?docid=%s' -## prefix_gdoc_id_res = 'document:' -# -# def google_docs_get(self, cr, uid, model, id): -# attachment = self.search(cr, uid, [('res_model', '=', model), ('res_id', '=', id), ('type', '=', 'url'), ('url', 'like', 'https://docs.oogle.com')]) -# if attachment: -# return self.read(cr, uid, attachment)[0]['url'] -# else: -# url = self.pad_generate_url(cr, uid, model, id) -# self.create(cr, uid, { -# 'res_model' : model, -# 'res_id' : id, -# 'type' : 'url', -# 'name' : 'Pad', -# 'url' : url, -# }) -# return url -# -# def generate_name(self, cr, uid, model, id): -# template_vars = { -# 'db' : cr.dbname, -# 'model' : model, -# 'id' : id, -# 'salt' : salt, -# 'name' : self.pool.get(model).name_get(cr,uid,[id])[0], -# } -# return pad_url_template % template_vars -# -# -# def button_add_google_docs_google_docs_add_doc(self, cr, uid, model, id): -# #pad_url_template = self.pool.get('res.users').browse(cr,uid,[uid])[0].company_id.pad_url_template -# #s = string.ascii_uppercase + string.digits -# #salt = ''.join([s[random.randint(0, len(s) - 1)] for i in range(8)]) -# -# # i lookup in the table google_docs.templates to check the policy -# -# # if multiple: 1 -# -# # if i find a template i will duplicate the template -# -# # else empty 'word' text -# -# # else -# # if no document exists do like 1 -^ -# # else -# # jumpt to the existing document -# - class google_docs(osv.osv): _name = 'google.docs' -- cgit v1.2.3 From 841f8b12b413dd7a0d4091182d092128f27da5f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20L=C3=B3pez=20L=C3=B3pez=20=28OpenERP=29?= Date: Tue, 28 Feb 2012 15:46:23 +0100 Subject: [imp] gdata code bzr revid: rlo@openerp.com-20120228144623-4bk6lsnthk2elqbv --- addons/google_docs/google_docs.py | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'addons/google_docs/google_docs.py') diff --git a/addons/google_docs/google_docs.py b/addons/google_docs/google_docs.py index 2f2c4919271..1dd632aab83 100644 --- a/addons/google_docs/google_docs.py +++ b/addons/google_docs/google_docs.py @@ -49,38 +49,40 @@ google_docs.copy_gdoc() if context==None: context={} - template_vars = { + '''template_vars = { 'db' : cr.dbname, 'model' : model, 'id' : id, 'salt' : salt, 'name' : '', - } + }''' name_template = 'Sales order %s' - # check template for the current model - model_obj = self.pool.get(model) - res_gdocs_obj = self.pool.get('google.docs') - domain = [('model' , '=', model_obj)] - gdoc = res_gdocs_obj.search(cr,uid,domain,context=context) - if not gdoc: - return -1 - # 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: return -2 + # check template for the current model + # TODO check module logic + '''model_obj = self.pool.get(model[0]) + res_gdocs_obj = self.pool.get('google.docs') + domain = [('model' , '=', model_obj)] + gdoc = res_gdocs_obj.search(cr,uid,domain,context=context) + if not gdoc: + + return -1 +''' # copy the document 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') - resource = client.get_resource_by_id(gdoc.gdocs_res_id) - copied_resource = client.copy_resource(entry=resource, title= self.name_template % (model, )) + resource = gdata.docs.data.Resource(gdata.docs.data.DOCUMENT_LABEL) + new_resource = client.post(entry=resource, uri='https://docs.google.com/feeds/default/private/full/') - return self.edit_url_template % (copied_resource.resource_id.text,) + return self.edit_url_template % (new_resource.resource_id.text,) ''' def get_documents_list(self, cr, uid, context=None): -- cgit v1.2.3 From f8213e68f0a1d5ffde27a47b70211a0cb205db9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20L=C3=B3pez=20L=C3=B3pez=20=28OpenERP=29?= Date: Wed, 29 Feb 2012 09:38:33 +0100 Subject: [imp] integration with google_base_account bzr revid: rlo@openerp.com-20120229083833-yd0wfg8x5ywc9e1c --- addons/google_docs/google_docs.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'addons/google_docs/google_docs.py') diff --git a/addons/google_docs/google_docs.py b/addons/google_docs/google_docs.py index 1dd632aab83..1c36533e614 100644 --- a/addons/google_docs/google_docs.py +++ b/addons/google_docs/google_docs.py @@ -23,7 +23,7 @@ GOOGLE DOCS ######################################### ''' - edit_url_template = 'https://docs.google.com/Edit?docid=%s' + edit_url_template = 'https://docs.google.com/document/d/%s/edit' prefix_gdoc_id_res = DOCUMENT_LABEL + ':' def copy_gdoc(self, cr, uid, model, context=None): @@ -61,6 +61,9 @@ google_docs.copy_gdoc() # check google_base_account users_obj = self.pool.get('res.users') user = users_obj.browse(cr, uid, [uid])[0] + print '%s' % user.__dict__ + print '%s' % user.gmail_user + print '%s' % user.gmail_password if not user.gmail_user or not user.gmail_password: return -2 @@ -81,7 +84,9 @@ google_docs.copy_gdoc() client.ClientLogin(user.gmail_user, user.gmail_password, client.source, service='writely') resource = gdata.docs.data.Resource(gdata.docs.data.DOCUMENT_LABEL) new_resource = client.post(entry=resource, uri='https://docs.google.com/feeds/default/private/full/') - + print new_resource.__dict__ + print new_resource.resource_id.text + print new_resource.resource_id return self.edit_url_template % (new_resource.resource_id.text,) ''' -- cgit v1.2.3 From 4c04da28b7e3c78785cbb51892b26facc1b15f1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20L=C3=B3pez=20L=C3=B3pez=20=28OpenERP=29?= Date: Wed, 29 Feb 2012 13:29:40 +0100 Subject: [imp] working... the only thing missing is linking from the model web to the gdoc web bzr revid: rlo@openerp.com-20120229122940-16h3bwa6j8zbz01s --- addons/google_docs/google_docs.py | 152 +++++++++----------------------------- 1 file changed, 35 insertions(+), 117 deletions(-) (limited to 'addons/google_docs/google_docs.py') diff --git a/addons/google_docs/google_docs.py b/addons/google_docs/google_docs.py index 1c36533e614..57cd9441566 100644 --- a/addons/google_docs/google_docs.py +++ b/addons/google_docs/google_docs.py @@ -4,162 +4,80 @@ import gdata.docs.client from gdata.client import RequestError from gdata.docs.service import DOCUMENT_LABEL -class google_docs(osv.osv): - _name = 'google.docs' +class google_docs_config(osv.osv): + _name = 'google.docs.config' + _inherit = 'ir.attachment' - _table = 'google_docs_templates' _columns = { - 'id': fields.integer('ID', readonly=True), 'model': fields.many2one('ir.model', 'Model'), - 'gdocs_res_id': fields.char('Google resource ID', size=64, translate=False), - 'name_template': fields.char('GDoc name template', size=64, translate=False) + 'gdocs_resource_id': fields.char('Google resource ID', size=64), + 'name_template': fields.char('GDoc name template', size=64) } - print ''' - -######################################### -GOOGLE DOCS - -######################################### + _defaults = { + 'name_template': 'Google Document' + } -''' edit_url_template = 'https://docs.google.com/document/d/%s/edit' prefix_gdoc_id_res = DOCUMENT_LABEL + ':' def copy_gdoc(self, cr, uid, model, context=None): + #import pdb; pdb.set_trace() '''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. @param model: the current model name. @param context: a standard dictionary for contextual values. @return the url of the copy itself. - @return -1 if the template hasn't been assigned yet. @return -2 if the google_base_account hasn't been configured yet. ''' - print ''' - -######################################### - -google_docs.copy_gdoc() - -######################################### - -''' if context==None: context={} - '''template_vars = { - 'db' : cr.dbname, - 'model' : model, - 'id' : id, - 'salt' : salt, - 'name' : '', - }''' name_template = 'Sales order %s' # check google_base_account users_obj = self.pool.get('res.users') user = users_obj.browse(cr, uid, [uid])[0] - print '%s' % user.__dict__ - print '%s' % user.gmail_user - print '%s' % user.gmail_password if not user.gmail_user or not user.gmail_password: return -2 - # check template for the current model - # TODO check module logic - '''model_obj = self.pool.get(model[0]) - res_gdocs_obj = self.pool.get('google.docs') - domain = [('model' , '=', model_obj)] - gdoc = res_gdocs_obj.search(cr,uid,domain,context=context) - if not gdoc: - - return -1 -''' - # copy the document + # create the document 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') resource = gdata.docs.data.Resource(gdata.docs.data.DOCUMENT_LABEL) - new_resource = client.post(entry=resource, uri='https://docs.google.com/feeds/default/private/full/') - print new_resource.__dict__ - print new_resource.resource_id.text - print new_resource.resource_id - return self.edit_url_template % (new_resource.resource_id.text,) - -''' - def get_documents_list(self, cr, uid, context=None): - ' ''Return the list of google documents available at the user's account. - @param cr: the current row from the database cursor. - @param uid: the current user ID, for security checks. - @param context: a standard dictionary for contextual values. - @return a list with information about the documents in form of tuples (document_name, document_resource_id). - @return -2 if the google_base_account hasn't been configured yet. - '' ' - - if context == None: - context = {} - - # 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: - return -2 - - # get the documents list - 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') + gdocs_resource = client.post(entry=resource, uri='https://docs.google.com/feeds/default/private/full/') + return gdocs_resource - return map(lambda doc: (doc.title.text, doc.resource_id.text[len(prefix_gdoc_id_res):]), filter(lambda r: r.resource_id.text.startswith(prefix_gdoc_id_res), client.get_all_resources())) -''' +class google_docs(osv.osv): + _name = 'google.docs' -''' - def set_model_document_template(self, cr, uid, model, resource_id, context=None): - '' 'Set the default document template for the specified model. This template doesn't have to be a google documents template itself, but just a document. - @param cr: current row for the database cursor. - @param uid: the current user ID, for security checks. - @param model: the current model name. - @param resource_id: resource_id associated to the chosen document. - @param context: a standard dictionary for contextual values. - @return 0 on successful execution. - @return -2 if the google_base_account hasn't been configured yet. - @return -3 if the given resource_id doesn't exist in the user's google docs account. - ' '' - if context == None: - context = {} + def doc_get(self, cr, uid, model, id, context=None): + google_docs_ref = self.pool.get('google.docs.config') + gdocs_resource_id = google_docs_ref.search(cr, uid, [('model', '=', model)]) - # 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: - return -2 + if gdocs_resource_id: + return google_docs_ref.edit_url_template % (gdocs_resource_id, ) + else: + gdocs_resource = google_docs_ref.copy_gdoc(cr, uid, model, context) + print gdocs_resource + if gdocs_resource == -2: + return gdocs_resource - # check resource_id - 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') - try: - client.get_resource_by_id(resource_id) - except RequestError: - return -3 + print gdocs_resource - # set the model document template - model_template_id = self.create(cr, uid, - { 'model': self.pool.get(model), - 'gdocs_res_id': resource_id + import pdb; pdb.set_trace() + # save the reference + gdocs_resource_id = gdocs_resource.resource_id.text[gdocs_resource.prefix_gdoc_id_res+1:] + google_docs_ref.create(cr, uid, { + 'model': model, + 'google_resource_id': gdocs_resource_id, + 'name': gdocs_resource_title.text, }) - - return 0 -''' - -class google_docs_folder(osv.osv): - _name = 'google.docs.folder' - _columns = { - 'res_id': fields.char('GDocs resource id', size=64, translate=False), - } + print gdocs_resource.resource_id.text + print gdocs_resource_id + return google_docs_ref.edit_url_template % (gdocs_resource_id,) -- cgit v1.2.3 From 854e18a73724b97107dcaf172c77855713fe7a18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20L=C3=B3pez=20L=C3=B3pez=20=28OpenERP=29?= Date: Wed, 29 Feb 2012 13:37:58 +0100 Subject: [imp]fixrkremove pdb statements bzr revid: rlo@openerp.com-20120229123758-0tcguv9olvul3trk --- addons/google_docs/google_docs.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'addons/google_docs/google_docs.py') diff --git a/addons/google_docs/google_docs.py b/addons/google_docs/google_docs.py index 57cd9441566..abc7d81e189 100644 --- a/addons/google_docs/google_docs.py +++ b/addons/google_docs/google_docs.py @@ -70,9 +70,8 @@ class google_docs(osv.osv): print gdocs_resource - import pdb; pdb.set_trace() # save the reference - gdocs_resource_id = gdocs_resource.resource_id.text[gdocs_resource.prefix_gdoc_id_res+1:] + gdocs_resource_id = gdocs_resource.resource_id.text[len(google_docs_ref.prefix_gdoc_id_res):] google_docs_ref.create(cr, uid, { 'model': model, 'google_resource_id': gdocs_resource_id, -- cgit v1.2.3 From 67ffbbac7a14a31d278043f1a5b962a41730ece1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20L=C3=B3pez=20L=C3=B3pez=20=28OpenERP=29?= Date: Wed, 29 Feb 2012 13:39:42 +0100 Subject: [fix] remove debug statements bzr revid: rlo@openerp.com-20120229123942-a3ntcfz15xgqek4g --- addons/google_docs/google_docs.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'addons/google_docs/google_docs.py') diff --git a/addons/google_docs/google_docs.py b/addons/google_docs/google_docs.py index abc7d81e189..e253d62ffbb 100644 --- a/addons/google_docs/google_docs.py +++ b/addons/google_docs/google_docs.py @@ -64,12 +64,9 @@ class google_docs(osv.osv): return google_docs_ref.edit_url_template % (gdocs_resource_id, ) else: gdocs_resource = google_docs_ref.copy_gdoc(cr, uid, model, context) - print gdocs_resource if gdocs_resource == -2: return gdocs_resource - print gdocs_resource - # save the reference gdocs_resource_id = gdocs_resource.resource_id.text[len(google_docs_ref.prefix_gdoc_id_res):] google_docs_ref.create(cr, uid, { @@ -77,6 +74,5 @@ class google_docs(osv.osv): 'google_resource_id': gdocs_resource_id, 'name': gdocs_resource_title.text, }) - print gdocs_resource.resource_id.text - print gdocs_resource_id + return google_docs_ref.edit_url_template % (gdocs_resource_id,) -- cgit v1.2.3 From 1ade3b205fc01dc4d476fa295d8e046a44755b19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20L=C3=B3pez=20L=C3=B3pez=20=28OpenERP=29?= Date: Wed, 29 Feb 2012 18:23:19 +0100 Subject: [fix] bzr revid: rlo@openerp.com-20120229172319-rzwcu1egrhw9ggms --- addons/google_docs/google_docs.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'addons/google_docs/google_docs.py') diff --git a/addons/google_docs/google_docs.py b/addons/google_docs/google_docs.py index e253d62ffbb..b60acd16197 100644 --- a/addons/google_docs/google_docs.py +++ b/addons/google_docs/google_docs.py @@ -55,11 +55,12 @@ class google_docs_config(osv.osv): class google_docs(osv.osv): _name = 'google.docs' - - def doc_get(self, cr, uid, model, id, context=None): + def doc_get(self, cr, uid, model, ids, context=None): google_docs_ref = self.pool.get('google.docs.config') - gdocs_resource_id = google_docs_ref.search(cr, uid, [('model', '=', model)]) - + gdocs_resource_id = google_docs_ref.search(cr, uid, [('model', '=', model), ('id', 'in', ids)]) + #print gdocs_resource_id + #print google_docs_ref.edit_url_template % (gdocs_resource_id, ) + #import pdb; pdb.set_trace() if gdocs_resource_id: return google_docs_ref.edit_url_template % (gdocs_resource_id, ) else: -- cgit v1.2.3 From cde742506ee92500e9cd2e4c41b041613d225442 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20L=C3=B3pez=20L=C3=B3pez=20=28OpenERP=29?= Date: Wed, 29 Feb 2012 19:45:20 +0100 Subject: [fix] logic... bzr revid: rlo@openerp.com-20120229184520-vs679o9drs1vls4r --- addons/google_docs/google_docs.py | 97 ++++++++++++++++++++++++++------------- 1 file changed, 65 insertions(+), 32 deletions(-) (limited to 'addons/google_docs/google_docs.py') diff --git a/addons/google_docs/google_docs.py b/addons/google_docs/google_docs.py index b60acd16197..689f5522cd3 100644 --- a/addons/google_docs/google_docs.py +++ b/addons/google_docs/google_docs.py @@ -4,24 +4,25 @@ import gdata.docs.client from gdata.client import RequestError from gdata.docs.service import DOCUMENT_LABEL -class google_docs_config(osv.osv): - _name = 'google.docs.config' +class google_docs_ir_attachment(osv.osv): _inherit = 'ir.attachment' - _columns = { - 'model': fields.many2one('ir.model', 'Model'), - 'gdocs_resource_id': fields.char('Google resource ID', size=64), - 'name_template': fields.char('GDoc name template', size=64) - } - - _defaults = { - 'name_template': 'Google Document' - } + def _auth(self, cr, uid): + # 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: + return -2 - edit_url_template = 'https://docs.google.com/document/d/%s/edit' - prefix_gdoc_id_res = DOCUMENT_LABEL + ':' + # 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') + + return client - def copy_gdoc(self, cr, uid, model, context=None): + def create_empty_gdoc(self, cr, uid, model, context=None): #import pdb; pdb.set_trace() '''Associate a copy of the gdoc identified by 'gdocs_res_id' to the current entity. @param cr: the current row from the database cursor. @@ -35,45 +36,77 @@ class google_docs_config(osv.osv): if context==None: context={} - name_template = 'Sales order %s' - - # 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: + client = _auth(cr, uid) + if client == -2: return -2 - # create the document - 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') resource = gdata.docs.data.Resource(gdata.docs.data.DOCUMENT_LABEL) gdocs_resource = client.post(entry=resource, uri='https://docs.google.com/feeds/default/private/full/') return gdocs_resource + def copy_gdoc(self, cr, uid, model, gdocs_resource_id, context=None): + if context==None: + context={} + + client = _auth(cr, uid) + if client == -2: + return -2 + + # fetch and copy the original document + original_resource = client.get_resource_by_id(gdocs_resource_id) + return client.copy_resource(entry=original_resource) + + def gdoc_get(self, cr, uid, model, context=None): + google_docs_config_ref = self.pool.get('google.docs.config') + google_template_ids = google_docs_config_ref.search(cr, uid, [('model', '=', model)]) + if not google_template_ids: + # there isn't any template. Create an empty doc. + return self.create_gdoc(cr, uid, model, context) + + # otherwise, copy document from existing template + return self.copy_gdoc(cr, uid, model, google_template_ids[0].gdocs_resource_id + +class google_docs_config(osv.osv): + _name = 'google.docs.config' + + _columns = { + 'model_id': fields.many2one('ir.model', 'Model'), + 'gdocs_resource_id': fields.char('Google resource ID', size=64), + 'name_template': fields.char('GDoc name template', size=64), + 'url': fields.char('url for the template', size=122), + } + + _defaults = { + 'name_template': 'Google Document' + } + + edit_url_template = 'https://docs.google.com/document/d/%s/edit' + prefix_gdoc_id_res = DOCUMENT_LABEL + ':' + + class google_docs(osv.osv): _name = 'google.docs' - def doc_get(self, cr, uid, model, ids, context=None): - google_docs_ref = self.pool.get('google.docs.config') + def doc_get(self, cr, uid, model, ids, context=None):# TODO fix logic here + google_docs_ref = self.pool.get('ir.attachment') gdocs_resource_id = google_docs_ref.search(cr, uid, [('model', '=', model), ('id', 'in', ids)]) #print gdocs_resource_id #print google_docs_ref.edit_url_template % (gdocs_resource_id, ) - #import pdb; pdb.set_trace() if gdocs_resource_id: return google_docs_ref.edit_url_template % (gdocs_resource_id, ) else: - gdocs_resource = google_docs_ref.copy_gdoc(cr, uid, model, context) + ir_attachment_res = self.pool.get('ir.attachment') + gdocs_resource = ir_attachment_res.create_empty_gdoc(cr, uid, model, context) if gdocs_resource == -2: return gdocs_resource # save the reference gdocs_resource_id = gdocs_resource.resource_id.text[len(google_docs_ref.prefix_gdoc_id_res):] + import pdb; pdb.set_trace() google_docs_ref.create(cr, uid, { - 'model': model, - 'google_resource_id': gdocs_resource_id, - 'name': gdocs_resource_title.text, + 'model_id': self.pool.get(model), + 'gdocs_resource_id': gdocs_resource_id, + 'name': gdocs_resource.title.text, }) return google_docs_ref.edit_url_template % (gdocs_resource_id,) -- cgit v1.2.3 From 2947f6dbb8563bfab55d457e9b1c0cc99f0fc4f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20L=C3=B3pez=20L=C3=B3pez=20=28OpenERP=29?= Date: Thu, 1 Mar 2012 15:45:07 +0100 Subject: [imp] add middleware support for spreadsheets and presentations bzr revid: rlo@openerp.com-20120301144507-k9kqsrdzwi0h8mf5 --- addons/google_docs/google_docs.py | 97 ++++++++++++++++++++++++--------------- 1 file changed, 61 insertions(+), 36 deletions(-) (limited to 'addons/google_docs/google_docs.py') diff --git a/addons/google_docs/google_docs.py b/addons/google_docs/google_docs.py index 689f5522cd3..3e6c398b155 100644 --- a/addons/google_docs/google_docs.py +++ b/addons/google_docs/google_docs.py @@ -22,39 +22,70 @@ class google_docs_ir_attachment(osv.osv): return client - def create_empty_gdoc(self, cr, uid, model, context=None): + def create_empty_google_doc(self, cr, uid, model, id, context=None): #import pdb; pdb.set_trace() '''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. @param model: the current model name. @param context: a standard dictionary for contextual values. - @return the url of the copy itself. + @return the document object. @return -2 if the google_base_account hasn't been configured yet. ''' - if context==None: + if context is None: context={} - client = _auth(cr, uid) + # authenticate + client = self._auth(cr, uid) if client == -2: return -2 - resource = gdata.docs.data.Resource(gdata.docs.data.DOCUMENT_LABEL) - gdocs_resource = client.post(entry=resource, uri='https://docs.google.com/feeds/default/private/full/') + if 'type' not in context: + context['type'] = 'text' + + # create the document in google docs + if context['type']=='slide': + local_resource = gdata.docs.data.Resource(gdata.docs.data.PRESENTATION_LABEL) + elif context['type']=='spreadsheet': + 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 + self.create(cr, uid, { + 'model': context['active_model'], #model, + 'res_id': context['active_id'], + 'type': 'url', + #'name': TODO pending from the working config + 'url': gdocs_resource.get_alternate_link().href + }) + return gdocs_resource def copy_gdoc(self, cr, uid, model, gdocs_resource_id, context=None): - if context==None: + if context is None: context={} - client = _auth(cr, uid) + client = self._auth(cr, uid) if client == -2: return -2 # fetch and copy the original document original_resource = client.get_resource_by_id(gdocs_resource_id) - return client.copy_resource(entry=original_resource) + copy_resource = client.copy_resource(entry=original_resource) + + # register into the db + self.create(cr, uid, { + 'model': context['active_model'], + 'res_id': context['active_id'], + 'type': 'url', + #'name': TODO pending from the working config + 'url': copy_resource.get_alternate_link().href + }) + + return copy_resource def gdoc_get(self, cr, uid, model, context=None): google_docs_config_ref = self.pool.get('google.docs.config') @@ -64,7 +95,7 @@ class google_docs_ir_attachment(osv.osv): return self.create_gdoc(cr, uid, model, context) # otherwise, copy document from existing template - return self.copy_gdoc(cr, uid, model, google_template_ids[0].gdocs_resource_id + return self.copy_gdoc(cr, uid, model, google_template_ids[0].gdocs_resource_id) class google_docs_config(osv.osv): _name = 'google.docs.config' @@ -72,41 +103,35 @@ class google_docs_config(osv.osv): _columns = { 'model_id': fields.many2one('ir.model', 'Model'), 'gdocs_resource_id': fields.char('Google resource ID', size=64), - 'name_template': fields.char('GDoc name template', size=64), - 'url': fields.char('url for the template', size=122), + 'name_template': fields.char('GDoc name template ', size=64, help='This is the name which appears on google side'), + 'name': fields.char('Name', size=64, help='This is the attachment\'s name. As well, it appears on the panel.') + # 'multi': fields.boolean('Multiple documents') } _defaults = { 'name_template': 'Google Document' } - edit_url_template = 'https://docs.google.com/document/d/%s/edit' - prefix_gdoc_id_res = DOCUMENT_LABEL + ':' class google_docs(osv.osv): _name = 'google.docs' def doc_get(self, cr, uid, model, ids, context=None):# TODO fix logic here - google_docs_ref = self.pool.get('ir.attachment') - gdocs_resource_id = google_docs_ref.search(cr, uid, [('model', '=', model), ('id', 'in', ids)]) - #print gdocs_resource_id - #print google_docs_ref.edit_url_template % (gdocs_resource_id, ) - if gdocs_resource_id: - return google_docs_ref.edit_url_template % (gdocs_resource_id, ) - else: - ir_attachment_res = self.pool.get('ir.attachment') - gdocs_resource = ir_attachment_res.create_empty_gdoc(cr, uid, model, context) - if gdocs_resource == -2: - return gdocs_resource - - # save the reference - gdocs_resource_id = gdocs_resource.resource_id.text[len(google_docs_ref.prefix_gdoc_id_res):] - import pdb; pdb.set_trace() - google_docs_ref.create(cr, uid, { - 'model_id': self.pool.get(model), - 'gdocs_resource_id': gdocs_resource_id, - 'name': gdocs_resource.title.text, - }) - - return google_docs_ref.edit_url_template % (gdocs_resource_id,) + google_docs_config_ref = self.pool.get('google.docs.config') + ir_attachment_ref = self.pool.get('ir.attachment') + google_docs_config = google_docs_config_ref.search(cr, uid, [('model_id', '=', model)]) + + if not google_docs_config: + google_document = ir_attachment_ref.create_empty_google_doc(cr, uid, model, ids, context) + #else: + + + print google_docs_config + + if not google_docs_config: + return -1 + + + + return 0 -- cgit v1.2.3 From 663a525f76ccf263dbb37b451a9c7f2898217a2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20L=C3=B3pez=20L=C3=B3pez=20=28OpenERP=29?= Date: Thu, 1 Mar 2012 16:25:30 +0100 Subject: [imp] integrate frontend - middleware bzr revid: rlo@openerp.com-20120301152530-2ldz1w96y4pu2x9w --- addons/google_docs/google_docs.py | 47 ++++++++++++--------------------------- 1 file changed, 14 insertions(+), 33 deletions(-) (limited to 'addons/google_docs/google_docs.py') diff --git a/addons/google_docs/google_docs.py b/addons/google_docs/google_docs.py index 3e6c398b155..040dce932ea 100644 --- a/addons/google_docs/google_docs.py +++ b/addons/google_docs/google_docs.py @@ -22,32 +22,26 @@ class google_docs_ir_attachment(osv.osv): return client - def create_empty_google_doc(self, cr, uid, model, id, context=None): + def create_empty_google_doc(self, cr, uid, model, id, type_doc): #import pdb; pdb.set_trace() '''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. @param model: the current model name. - @param context: a standard dictionary for contextual values. + @param type_doc: text, spreadsheet or slide. @return the document object. @return -2 if the google_base_account hasn't been configured yet. ''' - if context is None: - context={} - # authenticate client = self._auth(cr, uid) if client == -2: return -2 - if 'type' not in context: - context['type'] = 'text' - # create the document in google docs - if context['type']=='slide': + if type_doc=='slide': local_resource = gdata.docs.data.Resource(gdata.docs.data.PRESENTATION_LABEL) - elif context['type']=='spreadsheet': + elif type_doc=='spreadsheet': local_resource = gdata.docs.data.Resource(gdata.docs.data.SPREADSHEET_LABEL) else: local_resource = gdata.docs.data.Resource(gdata.docs.data.DOCUMENT_LABEL) @@ -55,8 +49,8 @@ class google_docs_ir_attachment(osv.osv): # register into the db self.create(cr, uid, { - 'model': context['active_model'], #model, - 'res_id': context['active_id'], + 'model': model, + 'res_id': ids[0], 'type': 'url', #'name': TODO pending from the working config 'url': gdocs_resource.get_alternate_link().href @@ -64,7 +58,7 @@ class google_docs_ir_attachment(osv.osv): return gdocs_resource - def copy_gdoc(self, cr, uid, model, gdocs_resource_id, context=None): + def copy_gdoc(self, cr, uid, model, id): if context is None: context={} @@ -78,8 +72,8 @@ class google_docs_ir_attachment(osv.osv): # register into the db self.create(cr, uid, { - 'model': context['active_model'], - 'res_id': context['active_id'], + 'model': model, + 'res_id': id[0], 'type': 'url', #'name': TODO pending from the working config 'url': copy_resource.get_alternate_link().href @@ -87,16 +81,6 @@ class google_docs_ir_attachment(osv.osv): return copy_resource - def gdoc_get(self, cr, uid, model, context=None): - google_docs_config_ref = self.pool.get('google.docs.config') - google_template_ids = google_docs_config_ref.search(cr, uid, [('model', '=', model)]) - if not google_template_ids: - # there isn't any template. Create an empty doc. - return self.create_gdoc(cr, uid, model, context) - - # otherwise, copy document from existing template - return self.copy_gdoc(cr, uid, model, google_template_ids[0].gdocs_resource_id) - class google_docs_config(osv.osv): _name = 'google.docs.config' @@ -117,21 +101,18 @@ class google_docs_config(osv.osv): class google_docs(osv.osv): _name = 'google.docs' - def doc_get(self, cr, uid, model, ids, context=None):# TODO fix logic here + def doc_get(self, cr, uid, model, id, type_doc):# TODO fix logic here google_docs_config_ref = self.pool.get('google.docs.config') ir_attachment_ref = self.pool.get('ir.attachment') google_docs_config = google_docs_config_ref.search(cr, uid, [('model_id', '=', model)]) - + if not google_docs_config: - google_document = ir_attachment_ref.create_empty_google_doc(cr, uid, model, ids, context) - #else: - + google_document = ir_attachment_ref.create_empty_google_doc(cr, uid, model, ids, type_doc) + else: + google_document = ir_attachment_ref.copy_gdoc(cr, uid, model, id) print google_docs_config if not google_docs_config: return -1 - - - return 0 -- cgit v1.2.3 From 65d257d4e9fd9bee1c6ab82e63f4f122aa2ffe41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20L=C3=B3pez=20L=C3=B3pez=20=28OpenERP=29?= Date: Thu, 1 Mar 2012 16:28:05 +0100 Subject: [imp] bzr revid: rlo@openerp.com-20120301152805-p7wosq6x4johbosj --- addons/google_docs/google_docs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'addons/google_docs/google_docs.py') diff --git a/addons/google_docs/google_docs.py b/addons/google_docs/google_docs.py index 040dce932ea..34b4e5a16ed 100644 --- a/addons/google_docs/google_docs.py +++ b/addons/google_docs/google_docs.py @@ -107,7 +107,7 @@ class google_docs(osv.osv): google_docs_config = google_docs_config_ref.search(cr, uid, [('model_id', '=', model)]) if not google_docs_config: - google_document = ir_attachment_ref.create_empty_google_doc(cr, uid, model, ids, type_doc) + google_document = ir_attachment_ref.create_empty_google_doc(cr, uid, model, id, type_doc) else: google_document = ir_attachment_ref.copy_gdoc(cr, uid, model, id) -- cgit v1.2.3 From 9afb5cfe64b8f67e4ccfe6e048046fb6937aeef0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20L=C3=B3pez=20L=C3=B3pez=20=28OpenERP=29?= Date: Fri, 2 Mar 2012 09:30:13 +0100 Subject: [imp] py bzr revid: rlo@openerp.com-20120302083013-4pvtkjma36ovlzhy --- addons/google_docs/google_docs.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'addons/google_docs/google_docs.py') diff --git a/addons/google_docs/google_docs.py b/addons/google_docs/google_docs.py index 34b4e5a16ed..5e1f30e38fa 100644 --- a/addons/google_docs/google_docs.py +++ b/addons/google_docs/google_docs.py @@ -22,8 +22,8 @@ class google_docs_ir_attachment(osv.osv): return client - def create_empty_google_doc(self, cr, uid, model, id, type_doc): - #import pdb; pdb.set_trace() + def create_empty_google_doc(self, cr, uid, model, ids, type_doc): + import pdb; pdb.set_trace() '''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. @@ -49,16 +49,16 @@ class google_docs_ir_attachment(osv.osv): # register into the db self.create(cr, uid, { - 'model': model, + 'res_model': model, 'res_id': ids[0], 'type': 'url', - #'name': TODO pending from the working config + 'name': 'new_foo', # TODO pending from the working config 'url': gdocs_resource.get_alternate_link().href }) return gdocs_resource - def copy_gdoc(self, cr, uid, model, id): + def copy_gdoc(self, cr, uid, model, ids): if context is None: context={} @@ -72,10 +72,10 @@ class google_docs_ir_attachment(osv.osv): # register into the db self.create(cr, uid, { - 'model': model, - 'res_id': id[0], + 'res_model': model, + 'res_id': ids[0], 'type': 'url', - #'name': TODO pending from the working config + 'name': 'copy_foo', # TODO pending from the working config 'url': copy_resource.get_alternate_link().href }) -- cgit v1.2.3 From f0775d762e80c2fdd48b689b253bb02db14e569a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20L=C3=B3pez=20L=C3=B3pez=20=28OpenERP=29?= Date: Fri, 2 Mar 2012 09:40:06 +0100 Subject: [imp] kind of working, just the configuration is missing bzr revid: rlo@openerp.com-20120302084006-m3qx6zfypl6g57r8 --- addons/google_docs/google_docs.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'addons/google_docs/google_docs.py') diff --git a/addons/google_docs/google_docs.py b/addons/google_docs/google_docs.py index 5e1f30e38fa..3f544c983bc 100644 --- a/addons/google_docs/google_docs.py +++ b/addons/google_docs/google_docs.py @@ -23,7 +23,6 @@ class google_docs_ir_attachment(osv.osv): return client def create_empty_google_doc(self, cr, uid, model, ids, type_doc): - import pdb; pdb.set_trace() '''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. @@ -52,7 +51,7 @@ class google_docs_ir_attachment(osv.osv): 'res_model': model, 'res_id': ids[0], 'type': 'url', - 'name': 'new_foo', # TODO pending from the working config + 'name': 'new_foo %s' % (type_doc,) , # TODO pending from the working config 'url': gdocs_resource.get_alternate_link().href }) @@ -75,7 +74,7 @@ class google_docs_ir_attachment(osv.osv): 'res_model': model, 'res_id': ids[0], 'type': 'url', - 'name': 'copy_foo', # TODO pending from the working config + 'name': 'copy_foo %s' (type_doc,) , # TODO pending from the working config 'url': copy_resource.get_alternate_link().href }) -- cgit v1.2.3 From ff1fc1a7e9476f33e8a580c0c1f8942e5004bf0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20L=C3=B3pez=20L=C3=B3pez=20=28OpenERP=29?= Date: Fri, 2 Mar 2012 11:35:05 +0100 Subject: [imp] bzr revid: rlo@openerp.com-20120302103505-em22nbb5chumfzuf --- addons/google_docs/google_docs.py | 43 ++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 10 deletions(-) (limited to 'addons/google_docs/google_docs.py') diff --git a/addons/google_docs/google_docs.py b/addons/google_docs/google_docs.py index 3f544c983bc..a63043e65ba 100644 --- a/addons/google_docs/google_docs.py +++ b/addons/google_docs/google_docs.py @@ -1,8 +1,31 @@ +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2012 OpenERP SA (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + from osv import osv, fields -import gdata.docs.data -import gdata.docs.client -from gdata.client import RequestError -from gdata.docs.service import DOCUMENT_LABEL +try: + import gdata.docs.data + import gdata.docs.client + from gdata.client import RequestError + from gdata.docs.service import DOCUMENT_LABEL +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')) class google_docs_ir_attachment(osv.osv): _inherit = 'ir.attachment' @@ -12,7 +35,7 @@ class google_docs_ir_attachment(osv.osv): 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: - return -2 + return False # login client = gdata.docs.client.DocsClient(source='openerp.com') @@ -29,13 +52,13 @@ class google_docs_ir_attachment(osv.osv): @param model: the current model name. @param type_doc: text, spreadsheet or slide. @return the document object. - @return -2 if the google_base_account hasn't been configured yet. + @return False if the google_base_account hasn't been configured yet. ''' # authenticate client = self._auth(cr, uid) - if client == -2: - return -2 + if client == False: + return False # create the document in google docs if type_doc=='slide': @@ -62,8 +85,8 @@ class google_docs_ir_attachment(osv.osv): context={} client = self._auth(cr, uid) - if client == -2: - return -2 + if client == False: + return False # fetch and copy the original document original_resource = client.get_resource_by_id(gdocs_resource_id) -- cgit v1.2.3 From 01e67d6dd52daae8e4a54202501167b451655ce9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20L=C3=B3pez=20L=C3=B3pez=20=28OpenERP=29?= Date: Mon, 5 Mar 2012 14:52:40 +0100 Subject: [imp] init config bzr revid: rlo@openerp.com-20120305135240-o1a4sjcerod4l7jh --- addons/google_docs/google_docs.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'addons/google_docs/google_docs.py') diff --git a/addons/google_docs/google_docs.py b/addons/google_docs/google_docs.py index a63043e65ba..c254b4944ea 100644 --- a/addons/google_docs/google_docs.py +++ b/addons/google_docs/google_docs.py @@ -104,7 +104,9 @@ class google_docs_ir_attachment(osv.osv): return copy_resource class google_docs_config(osv.osv): - _name = 'google.docs.config' + #_name = 'google.docs.config' + _inherit = 'res.users' + _description = 'User\'s gdocs config' _columns = { 'model_id': fields.many2one('ir.model', 'Model'), @@ -118,7 +120,19 @@ class google_docs_config(osv.osv): 'name_template': 'Google Document' } - + def create(self, cr, uid, vals, context=None): + res = super(users, self).create(cr, uid, vals, context=context) + model_obj=self.pool.get('ir.model') + if vals.get('context_gdocs_resource_id') and vals.get('context_model_id'): + self.write(cr, uid, #[vals['model_id']], {'member_ids':[(4, res)]}, + { + 'model_id': model_obj.get(cr, uid, vals.get('context_model_id'))[0], + 'gdocs_resource_id': vals.get('context_gdocs_resource_id'), + 'name_template': vals('context_name_template'), + 'name': vals('context_name'), + }, + context) + return res class google_docs(osv.osv): _name = 'google.docs' -- cgit v1.2.3 From ce1d3ce094db59b966adf02f8f0a841d84df1707 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20L=C3=B3pez=20L=C3=B3pez=20=28OpenERP=29?= Date: Mon, 5 Mar 2012 15:50:01 +0100 Subject: [imp] config view bzr revid: rlo@openerp.com-20120305145001-uut48z736imzbwtn --- addons/google_docs/google_docs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'addons/google_docs/google_docs.py') diff --git a/addons/google_docs/google_docs.py b/addons/google_docs/google_docs.py index c254b4944ea..dc4fc7d07b7 100644 --- a/addons/google_docs/google_docs.py +++ b/addons/google_docs/google_docs.py @@ -124,7 +124,7 @@ class google_docs_config(osv.osv): res = super(users, self).create(cr, uid, vals, context=context) model_obj=self.pool.get('ir.model') if vals.get('context_gdocs_resource_id') and vals.get('context_model_id'): - self.write(cr, uid, #[vals['model_id']], {'member_ids':[(4, res)]}, + self.write(cr, uid, { 'model_id': model_obj.get(cr, uid, vals.get('context_model_id'))[0], 'gdocs_resource_id': vals.get('context_gdocs_resource_id'), -- cgit v1.2.3 From fd89caf3cb964e150cb5b8cc7c224cc64ae32fe4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20L=C3=B3pez=20L=C3=B3pez=20=28OpenERP=29?= Date: Mon, 5 Mar 2012 17:11:15 +0100 Subject: [imp] bzr revid: rlo@openerp.com-20120305161115-i20h6xst3sg5n181 --- addons/google_docs/google_docs.py | 42 +++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'addons/google_docs/google_docs.py') diff --git a/addons/google_docs/google_docs.py b/addons/google_docs/google_docs.py index dc4fc7d07b7..8e093271c9e 100644 --- a/addons/google_docs/google_docs.py +++ b/addons/google_docs/google_docs.py @@ -103,10 +103,27 @@ class google_docs_ir_attachment(osv.osv): return copy_resource -class google_docs_config(osv.osv): - #_name = 'google.docs.config' +class google_docs(osv.osv): + _name = 'google.docs' + + def doc_get(self, cr, uid, model, id, type_doc):# TODO fix logic here + 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, [('model_id', '=', model)]) + + if not google_docs_config: + google_document = ir_attachment_ref.create_empty_google_doc(cr, uid, model, id, type_doc) + else: + google_document = ir_attachment_ref.copy_gdoc(cr, uid, model, id) + + print google_docs_config + + if not google_docs_config: + return -1 + +class users(osv.osv): _inherit = 'res.users' - _description = 'User\'s gdocs config' + _description = "User\'s gdocs config" _columns = { 'model_id': fields.many2one('ir.model', 'Model'), @@ -134,21 +151,4 @@ class google_docs_config(osv.osv): context) return res -class google_docs(osv.osv): - _name = 'google.docs' - - def doc_get(self, cr, uid, model, id, type_doc):# TODO fix logic here - google_docs_config_ref = self.pool.get('google.docs.config') - ir_attachment_ref = self.pool.get('ir.attachment') - google_docs_config = google_docs_config_ref.search(cr, uid, [('model_id', '=', model)]) - - if not google_docs_config: - google_document = ir_attachment_ref.create_empty_google_doc(cr, uid, model, id, type_doc) - else: - google_document = ir_attachment_ref.copy_gdoc(cr, uid, model, id) - - print google_docs_config - - if not google_docs_config: - return -1 - +google_docs_config() -- cgit v1.2.3 From 0102ccd723b7e5837f657cb5fdc643e4b0ec00a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20L=C3=B3pez=20L=C3=B3pez=20=28OpenERP=29?= Date: Tue, 6 Mar 2012 11:31:51 +0100 Subject: [imp] bzr revid: rlo@openerp.com-20120306103151-983wrsjoyw6rlo2h --- addons/google_docs/google_docs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'addons/google_docs/google_docs.py') diff --git a/addons/google_docs/google_docs.py b/addons/google_docs/google_docs.py index 8e093271c9e..1fc3daf7959 100644 --- a/addons/google_docs/google_docs.py +++ b/addons/google_docs/google_docs.py @@ -151,4 +151,4 @@ class users(osv.osv): context) return res -google_docs_config() +users() -- cgit v1.2.3 From 80229d461930b205f15d1d8d2651efe1913360ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20L=C3=B3pez=20L=C3=B3pez=20=28OpenERP=29?= Date: Tue, 6 Mar 2012 13:58:58 +0100 Subject: [imp] user config bzr revid: rlo@openerp.com-20120306125858-22qgeowa58mw419r --- addons/google_docs/google_docs.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'addons/google_docs/google_docs.py') diff --git a/addons/google_docs/google_docs.py b/addons/google_docs/google_docs.py index 1fc3daf7959..91c6d1daab4 100644 --- a/addons/google_docs/google_docs.py +++ b/addons/google_docs/google_docs.py @@ -126,15 +126,15 @@ class users(osv.osv): _description = "User\'s gdocs config" _columns = { - 'model_id': fields.many2one('ir.model', 'Model'), - 'gdocs_resource_id': fields.char('Google resource ID', size=64), - 'name_template': fields.char('GDoc name template ', size=64, help='This is the name which appears on google side'), - 'name': fields.char('Name', size=64, help='This is the attachment\'s name. As well, it appears on the panel.') + 'context_model_id': fields.many2one('ir.model', 'Model'), + 'context_gdocs_resource_id': fields.char('Google resource ID', size=64), + '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.') # 'multi': fields.boolean('Multiple documents') } _defaults = { - 'name_template': 'Google Document' + 'context_name_template': 'Google Document' } def create(self, cr, uid, vals, context=None): -- cgit v1.2.3 From a08205304ba18db7160c56ba4dc5502f36c689e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20L=C3=B3pez=20L=C3=B3pez=20=28OpenERP=29?= Date: Mon, 12 Mar 2012 15:41:31 +0100 Subject: [imp] bzr revid: rlo@openerp.com-20120312144131-k6sx56o0x699cr56 --- addons/google_docs/google_docs.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'addons/google_docs/google_docs.py') diff --git a/addons/google_docs/google_docs.py b/addons/google_docs/google_docs.py index 91c6d1daab4..874c8893ca6 100644 --- a/addons/google_docs/google_docs.py +++ b/addons/google_docs/google_docs.py @@ -109,7 +109,7 @@ class google_docs(osv.osv): def doc_get(self, cr, uid, model, id, type_doc):# TODO fix logic here 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, [('model_id', '=', model)]) + google_docs_config = google_docs_config_ref.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) @@ -121,20 +121,22 @@ class google_docs(osv.osv): if not google_docs_config: return -1 -class users(osv.osv): - _inherit = 'res.users' - _description = "User\'s gdocs config" +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_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.') - # 'multi': fields.boolean('Multiple documents') + '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') } _defaults = { - 'context_name_template': 'Google Document' + 'context_name_template': 'Google Document', + 'context_name': 'pr_%(name)', + 'context_multiple': False, } def create(self, cr, uid, vals, context=None): @@ -143,12 +145,13 @@ class users(osv.osv): if vals.get('context_gdocs_resource_id') and vals.get('context_model_id'): self.write(cr, uid, { - 'model_id': model_obj.get(cr, uid, vals.get('context_model_id'))[0], - 'gdocs_resource_id': vals.get('context_gdocs_resource_id'), - 'name_template': vals('context_name_template'), - 'name': vals('context_name'), + 'context_model_id': model_obj.get(cr, uid, vals.get('context_model_id'))[0], + 'context_gdocs_resource_id': vals.get('context_gdocs_resource_id'), + 'context_name_template': vals.get('context_name_template'), + 'context_name': self.context_name % {'name': vals.get('context_name')}, + 'context_multiple': vals.get('context_multiple'), }, context) return res -users() +config() -- cgit v1.2.3 From 416ffbb6350c45bc834974f36a3483348d58996a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20L=C3=B3pez=20L=C3=B3pez=20=28OpenERP=29?= Date: Wed, 14 Mar 2012 13:55:02 +0100 Subject: [imp] bzr revid: rlo@openerp.com-20120314125502-ca1g8cw7y3dm65e4 --- addons/google_docs/google_docs.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'addons/google_docs/google_docs.py') diff --git a/addons/google_docs/google_docs.py b/addons/google_docs/google_docs.py index 874c8893ca6..4d2533b9c0b 100644 --- a/addons/google_docs/google_docs.py +++ b/addons/google_docs/google_docs.py @@ -140,15 +140,15 @@ class config(osv.osv): } def create(self, cr, uid, vals, context=None): - res = super(users, self).create(cr, uid, vals, context=context) + res = super(config, self).create(cr, uid, vals, context=context) model_obj=self.pool.get('ir.model') if vals.get('context_gdocs_resource_id') and vals.get('context_model_id'): self.write(cr, uid, { - 'context_model_id': model_obj.get(cr, uid, vals.get('context_model_id'))[0], + 'context_model_id': model_obj.read(cr, uid, [vals.get('context_model_id')])[0], 'context_gdocs_resource_id': vals.get('context_gdocs_resource_id'), 'context_name_template': vals.get('context_name_template'), - 'context_name': self.context_name % {'name': vals.get('context_name')}, + 'context_name': vals.get('context_name'), 'context_multiple': vals.get('context_multiple'), }, context) -- cgit v1.2.3 From 38cd2dbe298f3b93b8ebc6dc87e016f0e6e09173 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20L=C3=B3pez=20L=C3=B3pez=20=28OpenERP=29?= Date: Wed, 14 Mar 2012 14:18:51 +0100 Subject: [imp] config form bzr revid: rlo@openerp.com-20120314131851-a3kzuzxt7f33fc9x --- addons/google_docs/google_docs.py | 15 --------------- 1 file changed, 15 deletions(-) (limited to 'addons/google_docs/google_docs.py') diff --git a/addons/google_docs/google_docs.py b/addons/google_docs/google_docs.py index 4d2533b9c0b..0d99f5f6d35 100644 --- a/addons/google_docs/google_docs.py +++ b/addons/google_docs/google_docs.py @@ -139,19 +139,4 @@ class config(osv.osv): 'context_multiple': False, } - def create(self, cr, uid, vals, context=None): - res = super(config, self).create(cr, uid, vals, context=context) - model_obj=self.pool.get('ir.model') - if vals.get('context_gdocs_resource_id') and vals.get('context_model_id'): - self.write(cr, uid, - { - 'context_model_id': model_obj.read(cr, uid, [vals.get('context_model_id')])[0], - 'context_gdocs_resource_id': vals.get('context_gdocs_resource_id'), - 'context_name_template': vals.get('context_name_template'), - 'context_name': vals.get('context_name'), - 'context_multiple': vals.get('context_multiple'), - }, - context) - return res - config() -- cgit v1.2.3 From 78903a8554d776632a17cde897ddcd2a7093b329 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20L=C3=B3pez=20L=C3=B3pez=20=28OpenERP=29?= Date: Wed, 14 Mar 2012 16:29:29 +0100 Subject: [imp] bzr revid: rlo@openerp.com-20120314152929-gqshx94zrcn34qzk --- addons/google_docs/google_docs.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'addons/google_docs/google_docs.py') diff --git a/addons/google_docs/google_docs.py b/addons/google_docs/google_docs.py index 0d99f5f6d35..e78444fb045 100644 --- a/addons/google_docs/google_docs.py +++ b/addons/google_docs/google_docs.py @@ -139,4 +139,11 @@ class config(osv.osv): 'context_multiple': False, } + def has_config_set(self, cr, uid, model): + print model + import pdb + pdb.set_trace() + domain = [('context_model_id', '=', model)] + return self.search_count(cr, uid, domain) != 0 + config() -- cgit v1.2.3 From ebb97da4d16ffdbf74091bc6742f1f175ac0142b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20L=C3=B3pez=20L=C3=B3pez=20=28OpenERP=29?= Date: Fri, 16 Mar 2012 10:00:54 +0100 Subject: [fix] fix according to requirements bzr revid: rlo@openerp.com-20120316090054-0datu37ojj98lx13 --- addons/google_docs/google_docs.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'addons/google_docs/google_docs.py') diff --git a/addons/google_docs/google_docs.py b/addons/google_docs/google_docs.py index e78444fb045..e822bb304bf 100644 --- a/addons/google_docs/google_docs.py +++ b/addons/google_docs/google_docs.py @@ -106,7 +106,7 @@ class google_docs_ir_attachment(osv.osv): class google_docs(osv.osv): _name = 'google.docs' - def doc_get(self, cr, uid, model, id, type_doc):# TODO fix logic here + 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)]) @@ -139,11 +139,11 @@ class config(osv.osv): 'context_multiple': False, } - def has_config_set(self, cr, uid, model): - print model - import pdb - pdb.set_trace() + def get_config(self, cr, uid, model): domain = [('context_model_id', '=', model)] - return self.search_count(cr, uid, domain) != 0 + if self.search_count(cr, uid, domain) != 0: + return False + else: + return self.search(cr, uid, domain) config() -- cgit v1.2.3 From 9d5db695ee3e1cfc1f0d306bccf117640a14927b Mon Sep 17 00:00:00 2001 From: MVA Date: Mon, 19 Mar 2012 11:31:32 +0100 Subject: [REF] correct the code and change the view files bzr revid: mva@openerp.com-20120319103132-av7c09avg4p0xgt3 --- addons/google_docs/google_docs.py | 51 ++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 25 deletions(-) (limited to 'addons/google_docs/google_docs.py') 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)] -- cgit v1.2.3 From f77cecb90c39041267455b05b23764f85e6783a5 Mon Sep 17 00:00:00 2001 From: MVA Date: Tue, 20 Mar 2012 17:03:20 +0100 Subject: [IMP] add oauth bzr revid: mva@openerp.com-20120320160320-tykxuosgpq1r28ag --- addons/google_docs/google_docs.py | 52 +++++++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 13 deletions(-) (limited to 'addons/google_docs/google_docs.py') diff --git a/addons/google_docs/google_docs.py b/addons/google_docs/google_docs.py index d37f28eb349..09bb1879bdd 100644 --- a/addons/google_docs/google_docs.py +++ b/addons/google_docs/google_docs.py @@ -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]) -- cgit v1.2.3 From dda93ab1ec568c66cc36d7a74ea093f4c9f573e9 Mon Sep 17 00:00:00 2001 From: MVA Date: Fri, 23 Mar 2012 11:29:04 +0100 Subject: [REF] refactore the oauth connexion bzr revid: mva@openerp.com-20120323102904-v72btptb9a4pnvht --- addons/google_docs/google_docs.py | 85 ++++++++++++++++++++++++++------------- 1 file changed, 56 insertions(+), 29 deletions(-) (limited to 'addons/google_docs/google_docs.py') diff --git a/addons/google_docs/google_docs.py b/addons/google_docs/google_docs.py index 09bb1879bdd..8257f595db1 100644 --- a/addons/google_docs/google_docs.py +++ b/addons/google_docs/google_docs.py @@ -25,7 +25,6 @@ try: 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')) @@ -57,7 +56,6 @@ class google_docs_ir_attachment(osv.osv): @return the document object. @return False if the google_base_account hasn't been configured yet. ''' - # authenticate ''' @@ -65,8 +63,8 @@ class google_docs_ir_attachment(osv.osv): if client == False: return False ''' - client = self.pool.get('google.oauth') - client.login(cr,uid,ids,context=context) + client = self.pool.get('google.oauth').login(cr,uid,ids) + # create the document in google docs if type_doc=='slide': @@ -77,7 +75,7 @@ class google_docs_ir_attachment(osv.osv): local_resource = gdata.docs.data.Resource(gdata.docs.data.DOCUMENT_LABEL) #create a new doc in Google Docs - gdocs_resource = client.Post(entry=local_resource, uri='https://docs.google.com/feeds/default/private/full/') + #gdocs_resource = client.post(entry=local_resource, uri='https://docs.google.com/feeds/default/private/full/') # register into the db self.create(cr, uid, { @@ -85,16 +83,17 @@ class google_docs_ir_attachment(osv.osv): 'res_id': ids[0], 'type': 'url', 'name': 'new_foo %s' % (type_doc,) , # TODO pending from the working config - 'url': gdocs_resource.get_alternate_link().href + 'url': ''#gdocs_resource.get_alternate_link().href },context=context) - return gdocs_resource + return 1 def copy_gdoc(self, cr, uid, model, ids,context=None): - client = self._auth(cr, uid) - if client == False: - return False + #client = self._auth(cr, uid) + #with oauth already connect check for the correct token + #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) @@ -154,23 +153,51 @@ config() class oauth (osv.osv): _name = 'google.oauth' + + ''' + def open_url(self,uid,ids,url,context=None): + return {'type' : 'ir.actions.act_url', + 'url' : url, + 'target': 'new', + } + ''' 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]) + + # subscribe the google API + CONSUMER_KEY = '751376579939.apps.googleusercontent.com' + CONSUMER_SECRET = '_KGpgyO8DZIseyG3N-j-h8gN' + + + local_resource = gdata.docs.data.Resource(gdata.docs.data.DOCUMENT_LABEL) + SCOPES = ['https://docs.google.com/feeds/'] #select the google service + + client = gdata.docs.client.DocsClient(source='openerp.com') + + #the callback url + oauth_callback_url = 'http://127.0.0.1:8069/'#TODO give a correct dynamic url + + #create a temporary token need to create a google authorization + request_token = client.GetOAuthToken(SCOPES, oauth_callback_url, CONSUMER_KEY, CONSUMER_SECRET) + #create an autorization google link + auth_url = request_token.generate_authorization_url() + #openthe link in your browser + webbrowser.open(str(auth_url)) + + #when you accept the autorization you are linked in your callback url + #you need to catch this url for the moment I copy past it in a raw_input + url_after=raw_input() + + #create an autorization token + request_token_authorized = gdata.gauth.AuthorizeRequestToken(request_token, url_after) + #upgrade the token + access_token = client.GetAccessToken(request_token_authorized) + + + #when your access token you can connect your google services + client.auth_token = gdata.gauth.OAuthHmacToken(CONSUMER_KEY, + CONSUMER_SECRET, + access_token.token, + access_token.token_secret, + gdata.gauth.ACCESS_TOKEN) + + return client -- cgit v1.2.3 From 3590c952ec73a4b933dfac889ffb20838475f345 Mon Sep 17 00:00:00 2001 From: MVA Date: Wed, 28 Mar 2012 10:29:48 +0200 Subject: [IMP] add gdata docs library in google base account remove oauth authentification and replace with google_login method in google_base_account remove unuse button in sidebar and correct the copy_resource method bzr revid: mva@openerp.com-20120328082948-7my72vqn0gcbsf2l --- addons/google_docs/google_docs.py | 129 +++++++++----------------------------- 1 file changed, 31 insertions(+), 98 deletions(-) (limited to 'addons/google_docs/google_docs.py') diff --git a/addons/google_docs/google_docs.py b/addons/google_docs/google_docs.py index 8257f595db1..bba8524023a 100644 --- a/addons/google_docs/google_docs.py +++ b/addons/google_docs/google_docs.py @@ -25,7 +25,6 @@ try: from gdata.client import RequestError from gdata.docs.service import DOCUMENT_LABEL import gdata.auth - 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')) @@ -33,17 +32,17 @@ class google_docs_ir_attachment(osv.osv): _inherit = 'ir.attachment' 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: - 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') #authentification in a gmail account + ''' + Connexion with google base account + @return client object for connexion + ''' + #pool the google.login in google_base_account + google_pool = self.pool.get('google.login') + + #get gmail password and login + user_config = google_pool.default_get( cr, uid, {'user' : '' , 'password' : ''},context=context) + #login gmail account + client = google_pool.google_login( user_config['user'], user_config['password'], type='docs_client', context=context) return client @@ -56,47 +55,31 @@ 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 - ''' - client = self.pool.get('google.oauth').login(cr,uid,ids) - - + #login with the base account google module + client = self._auth(cr, uid,context=context) # create the document in google docs - if type_doc=='slide': - local_resource = gdata.docs.data.Resource(gdata.docs.data.PRESENTATION_LABEL) - elif type_doc=='spreadsheet': - local_resource = gdata.docs.data.Resource(gdata.docs.data.SPREADSHEET_LABEL) - else: - local_resource = gdata.docs.data.Resource(gdata.docs.data.DOCUMENT_LABEL) - - #create a new doc in Google Docs - #gdocs_resource = client.post(entry=local_resource, uri='https://docs.google.com/feeds/default/private/full/') - + local_resource = gdata.docs.data.Resource(gdata.docs.data.DOCUMENT_LABEL) + #create a new doc in Google Docs + gdocs_resource = client.post(entry=local_resource, uri='https://docs.google.com/feeds/default/private/full/') + name = gdocs_resource.title # register into the db self.create(cr, uid, { 'res_model': model, 'res_id': ids[0], 'type': 'url', - 'name': 'new_foo %s' % (type_doc,) , # TODO pending from the working config - 'url': ''#gdocs_resource.get_alternate_link().href + 'name': name, + 'url': gdocs_resource.get_alternate_link().href, },context=context) return 1 - def copy_gdoc(self, cr, uid, model, ids,context=None): - #client = self._auth(cr, uid) - #with oauth already connect check for the correct token - #if client == False: - # return False + def copy_gdoc(self, cr, uid, model, google_res_id, ids,context=None): + client = self._auth(cr, uid) # fetch and copy the original document - original_resource = client.get_resource_by_id(gdocs_resource_id) - copy_resource = client.copy_resource(entry=original_resource) + original_resource = client.get_resource_by_id(google_res_id) + #copy the document you choose in the configuration + copy_resource = client.copy_resource(original_resource,'copy_foo') # register into the db self.create(cr, uid, { @@ -104,7 +87,7 @@ class google_docs_ir_attachment(osv.osv): 'res_id': ids[0], 'type': 'url', 'name': 'file_name', - 'name': 'copy_foo %s' (type_doc,) , #TODO pending from the working config + 'name': 'copy_foo' , #TODO pending from the working config 'url': copy_resource.get_alternate_link().href },context=context) @@ -113,12 +96,14 @@ class google_docs_ir_attachment(osv.osv): class google_docs(osv.osv): _name = 'google.docs' - def doc_get(self, cr, uid, model, id, type_doc): + def doc_get(self, cr, uid, model, id, type_doc,context=None): ir_attachment_ref = self.pool.get('ir.attachment') google_docs_config = self.pool.get('google.docs.config').search(cr, uid, [('context_model_id', '=', model)]) - + # check if a model is configurate with a template if google_docs_config: - google_document = ir_attachment_ref.copy_gdoc(cr, uid, model, id) + for google_config in self.pool.get('google.docs.config').browse(cr,uid,google_docs_config,context=context): + google_res_id = google_config.context_gdocs_resource_id + google_document = ir_attachment_ref.copy_gdoc(cr, uid, model,google_res_id, id) else: google_document = ir_attachment_ref.create_empty_google_doc(cr, uid, model, id, type_doc) return -1 @@ -133,13 +118,11 @@ class config(osv.osv): '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') } _defaults = { 'context_name_template': 'Google Document', 'context_name': 'pr_%(name)', - 'context_multiple': False, } def get_config(self, cr, uid, model): domain = [('context_model_id', '=', model)] @@ -147,57 +130,7 @@ class config(osv.osv): return False else: return self.search(cr, uid, domain) -config() - - - -class oauth (osv.osv): - _name = 'google.oauth' - - ''' - def open_url(self,uid,ids,url,context=None): - return {'type' : 'ir.actions.act_url', - 'url' : url, - 'target': 'new', - } - ''' - def login(self,cr,uid,ids,context=None): - - # subscribe the google API - CONSUMER_KEY = '751376579939.apps.googleusercontent.com' - CONSUMER_SECRET = '_KGpgyO8DZIseyG3N-j-h8gN' - - - local_resource = gdata.docs.data.Resource(gdata.docs.data.DOCUMENT_LABEL) - SCOPES = ['https://docs.google.com/feeds/'] #select the google service - - client = gdata.docs.client.DocsClient(source='openerp.com') - - #the callback url - oauth_callback_url = 'http://127.0.0.1:8069/'#TODO give a correct dynamic url - - #create a temporary token need to create a google authorization - request_token = client.GetOAuthToken(SCOPES, oauth_callback_url, CONSUMER_KEY, CONSUMER_SECRET) - #create an autorization google link - auth_url = request_token.generate_authorization_url() - #openthe link in your browser - webbrowser.open(str(auth_url)) - - #when you accept the autorization you are linked in your callback url - #you need to catch this url for the moment I copy past it in a raw_input - url_after=raw_input() - - #create an autorization token - request_token_authorized = gdata.gauth.AuthorizeRequestToken(request_token, url_after) - #upgrade the token - access_token = client.GetAccessToken(request_token_authorized) +config() - #when your access token you can connect your google services - client.auth_token = gdata.gauth.OAuthHmacToken(CONSUMER_KEY, - CONSUMER_SECRET, - access_token.token, - access_token.token_secret, - gdata.gauth.ACCESS_TOKEN) - return client -- cgit v1.2.3 From 2f1baf8f40908b54db0950f596fbe98e35d7cf9a Mon Sep 17 00:00:00 2001 From: MVA Date: Wed, 28 Mar 2012 11:34:56 +0200 Subject: [IMP] replace the static name in the document name bzr revid: mva@openerp.com-20120328093456-7wgnnvizvg0r747i --- addons/google_docs/google_docs.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'addons/google_docs/google_docs.py') diff --git a/addons/google_docs/google_docs.py b/addons/google_docs/google_docs.py index bba8524023a..8c882a3422a 100644 --- a/addons/google_docs/google_docs.py +++ b/addons/google_docs/google_docs.py @@ -61,13 +61,13 @@ class google_docs_ir_attachment(osv.osv): local_resource = gdata.docs.data.Resource(gdata.docs.data.DOCUMENT_LABEL) #create a new doc in Google Docs gdocs_resource = client.post(entry=local_resource, uri='https://docs.google.com/feeds/default/private/full/') - name = gdocs_resource.title + # register into the db self.create(cr, uid, { 'res_model': model, 'res_id': ids[0], 'type': 'url', - 'name': name, + 'name': ('new_%s' % gdocs_resource.title.text), 'url': gdocs_resource.get_alternate_link().href, },context=context) @@ -86,8 +86,7 @@ class google_docs_ir_attachment(osv.osv): 'res_model': model, 'res_id': ids[0], 'type': 'url', - 'name': 'file_name', - 'name': 'copy_foo' , #TODO pending from the working config + 'name': 'copy_%s' % gdocs_resource.title.text, 'url': copy_resource.get_alternate_link().href },context=context) -- cgit v1.2.3 From c46481f1deb9e692058cd1ed42f9b96127ad6556 Mon Sep 17 00:00:00 2001 From: MVA Date: Wed, 28 Mar 2012 11:47:18 +0200 Subject: [IMP] add a raise error to check if configuration is ok bzr revid: mva@openerp.com-20120328094718-xk5brbglmeo49cid --- addons/google_docs/google_docs.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'addons/google_docs/google_docs.py') diff --git a/addons/google_docs/google_docs.py b/addons/google_docs/google_docs.py index 8c882a3422a..13d9634dcf8 100644 --- a/addons/google_docs/google_docs.py +++ b/addons/google_docs/google_docs.py @@ -43,7 +43,8 @@ class google_docs_ir_attachment(osv.osv): user_config = google_pool.default_get( cr, uid, {'user' : '' , 'password' : ''},context=context) #login gmail account client = google_pool.google_login( user_config['user'], user_config['password'], type='docs_client', context=context) - + if not client: + raise osv.except_osv(('Google Docs Error!'),("Check your google configuration in users/synchronization") ) return client def create_empty_google_doc(self, cr, uid, model, ids, type_doc,context=None): -- cgit v1.2.3 From 774aa481c2f60df74d8b01f03b00cad002d8e105 Mon Sep 17 00:00:00 2001 From: MVA Date: Wed, 28 Mar 2012 12:10:15 +0200 Subject: [IMP] correct the copy with the good document title bzr revid: mva@openerp.com-20120328101015-4v1fit8z3cno9y91 --- addons/google_docs/google_docs.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'addons/google_docs/google_docs.py') diff --git a/addons/google_docs/google_docs.py b/addons/google_docs/google_docs.py index 13d9634dcf8..1e6071cd716 100644 --- a/addons/google_docs/google_docs.py +++ b/addons/google_docs/google_docs.py @@ -78,16 +78,17 @@ class google_docs_ir_attachment(osv.osv): def copy_gdoc(self, cr, uid, model, google_res_id, ids,context=None): client = self._auth(cr, uid) # fetch and copy the original document + print 'test' original_resource = client.get_resource_by_id(google_res_id) - #copy the document you choose in the configuration - copy_resource = client.copy_resource(original_resource,'copy_foo') + #copy the document you choose in the configuration + copy_resource = client.copy_resource(original_resource,'copy_%s' % original_resource.title.text) # register into the db self.create(cr, uid, { 'res_model': model, 'res_id': ids[0], 'type': 'url', - 'name': 'copy_%s' % gdocs_resource.title.text, + 'name': 'copy_%s' % original_resource.title.text, 'url': copy_resource.get_alternate_link().href },context=context) -- cgit v1.2.3 From 95a86ec57dfb22569ed9b1bd8ea36ae44f9e6856 Mon Sep 17 00:00:00 2001 From: MVA Date: Wed, 28 Mar 2012 13:41:13 +0200 Subject: [IMP] add some comment and add a raise if the google resource is not correct bzr revid: mva@openerp.com-20120328114113-vspkkbvpdfnt3mho --- addons/google_docs/google_docs.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'addons/google_docs/google_docs.py') diff --git a/addons/google_docs/google_docs.py b/addons/google_docs/google_docs.py index 1e6071cd716..6e91ee64658 100644 --- a/addons/google_docs/google_docs.py +++ b/addons/google_docs/google_docs.py @@ -76,13 +76,18 @@ class google_docs_ir_attachment(osv.osv): return 1 def copy_gdoc(self, cr, uid, model, google_res_id, ids,context=None): + ''' + copy an existing document in google docs + ''' + client = self._auth(cr, uid) # fetch and copy the original document - print 'test' - original_resource = client.get_resource_by_id(google_res_id) - #copy the document you choose in the configuration - copy_resource = client.copy_resource(original_resource,'copy_%s' % original_resource.title.text) - + try: + original_resource = client.get_resource_by_id(google_res_id) + #copy the document you choose in the configuration + copy_resource = client.copy_resource(original_resource,'copy_%s' % original_resource.title.text) + except: + raise osv.except_osv(('Google Docs Error!'),("Your ressource id is not correct. You can find the id in the google docs URL") ) # register into the db self.create(cr, uid, { 'res_model': model, @@ -126,6 +131,10 @@ class config(osv.osv): 'context_name': 'pr_%(name)', } def get_config(self, cr, uid, model): + ''' + Method use with the js to hidde or show the add google doc button + @return : list of configuration ids or false + ''' domain = [('context_model_id', '=', model)] if self.search_count(cr, uid, domain) != 0: return False -- cgit v1.2.3 From d4152e970378881f82373d4e09c8d23eea1d2535 Mon Sep 17 00:00:00 2001 From: MVA Date: Fri, 30 Mar 2012 16:51:49 +0200 Subject: [IMP] change js remove unusfull code and the file name configuration bzr revid: mva@openerp.com-20120330145149-04gqj8lvleb9pa53 --- addons/google_docs/google_docs.py | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) (limited to 'addons/google_docs/google_docs.py') diff --git a/addons/google_docs/google_docs.py b/addons/google_docs/google_docs.py index 6e91ee64658..3045cbab279 100644 --- a/addons/google_docs/google_docs.py +++ b/addons/google_docs/google_docs.py @@ -47,7 +47,7 @@ class google_docs_ir_attachment(osv.osv): raise osv.except_osv(('Google Docs Error!'),("Check your google configuration in users/synchronization") ) return client - def create_empty_google_doc(self, cr, uid, model, ids, type_doc,context=None): + def create_empty_google_doc(self, cr, uid, name_gdocs, 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. @@ -62,24 +62,22 @@ class google_docs_ir_attachment(osv.osv): local_resource = gdata.docs.data.Resource(gdata.docs.data.DOCUMENT_LABEL) #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, { 'res_model': model, 'res_id': ids[0], 'type': 'url', - 'name': ('new_%s' % gdocs_resource.title.text), + 'name': 'Google Doc', 'url': gdocs_resource.get_alternate_link().href, },context=context) return 1 - def copy_gdoc(self, cr, uid, model, google_res_id, ids,context=None): + def copy_gdoc(self, cr, uid, name_gdocs, model, google_res_id, ids,context=None): ''' copy an existing document in google docs ''' - client = self._auth(cr, uid) # fetch and copy the original document try: @@ -93,7 +91,7 @@ class google_docs_ir_attachment(osv.osv): 'res_model': model, 'res_id': ids[0], 'type': 'url', - 'name': 'copy_%s' % original_resource.title.text, + 'name': name_gdocs, 'url': copy_resource.get_alternate_link().href },context=context) @@ -104,14 +102,20 @@ class google_docs(osv.osv): def doc_get(self, cr, uid, model, id, type_doc,context=None): ir_attachment_ref = self.pool.get('ir.attachment') - google_docs_config = self.pool.get('google.docs.config').search(cr, uid, [('context_model_id', '=', model)]) + pool_gdoc_config = self.pool.get('google.docs.config') + google_docs_config = pool_gdoc_config.search(cr, uid, [('model_id', '=', model)]) + name_gdocs='' + if google_docs_config: + name_gdocs = pool_gdoc_config.browse(cr,uid,google_docs_config,context=context)[0].name_template + print name_gdocs + # check if a model is configurate with a template if google_docs_config: for google_config in self.pool.get('google.docs.config').browse(cr,uid,google_docs_config,context=context): - google_res_id = google_config.context_gdocs_resource_id - google_document = ir_attachment_ref.copy_gdoc(cr, uid, model,google_res_id, id) + google_res_id = google_config.gdocs_resource_id + google_document = ir_attachment_ref.copy_gdoc(cr, uid,name_gdocs ,model,google_res_id, id) else: - google_document = ir_attachment_ref.create_empty_google_doc(cr, uid, model, id, type_doc) + google_document = ir_attachment_ref.create_empty_google_doc(cr, uid,name_gdocs, model, id, type_doc) return -1 @@ -120,24 +124,25 @@ class config(osv.osv): _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,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.'), + 'model_id': fields.many2one('ir.model', 'Model'), + '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'), + 'name_template': fields.char('GDoc name template ', size=64, help='This is the name which appears on google side'), } _defaults = { - 'context_name_template': 'Google Document', - 'context_name': 'pr_%(name)', + 'name_template': 'pr_%(name)', } def get_config(self, cr, uid, model): ''' Method use with the js to hidde or show the add google doc button @return : list of configuration ids or false ''' - domain = [('context_model_id', '=', model)] + domain = [('model_id', '=', model)] if self.search_count(cr, uid, domain) != 0: return False + # attached only one document to a model + if self.pool.get('ir.attachment').search_count(cr,uid,[('url','like','https://docs.google.com/document%')]) !=0: + return False else: return self.search(cr, uid, domain) -- cgit v1.2.3 From fb989dbfb7161b9f79ce5bf2024a5f13423b1b6f Mon Sep 17 00:00:00 2001 From: MVA Date: Mon, 2 Apr 2012 15:18:17 +0200 Subject: [IMP] change the way to name the attachement and change when you already have a google document the button will be hide bzr revid: mva@openerp.com-20120402131817-oxv227m8i11pfsjx --- addons/google_docs/google_docs.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'addons/google_docs/google_docs.py') diff --git a/addons/google_docs/google_docs.py b/addons/google_docs/google_docs.py index 3045cbab279..e195fcf21a6 100644 --- a/addons/google_docs/google_docs.py +++ b/addons/google_docs/google_docs.py @@ -105,9 +105,11 @@ class google_docs(osv.osv): pool_gdoc_config = self.pool.get('google.docs.config') google_docs_config = pool_gdoc_config.search(cr, uid, [('model_id', '=', model)]) name_gdocs='' + model_fields_dic = self.pool.get(model).read(cr,uid,id,[]) + if google_docs_config: name_gdocs = pool_gdoc_config.browse(cr,uid,google_docs_config,context=context)[0].name_template - print name_gdocs + name_gdocs = name_gdocs % model_fields_dic[0] # check if a model is configurate with a template if google_docs_config: @@ -130,22 +132,17 @@ class config(osv.osv): } _defaults = { - 'name_template': 'pr_%(name)', + 'name_template': 'pr_%(name)s', } - def get_config(self, cr, uid, model): + def get_config(self, cr, uid, ids, model,context=None): ''' Method use with the js to hidde or show the add google doc button @return : list of configuration ids or false ''' - domain = [('model_id', '=', model)] - if self.search_count(cr, uid, domain) != 0: - return False - # attached only one document to a model - if self.pool.get('ir.attachment').search_count(cr,uid,[('url','like','https://docs.google.com/document%')]) !=0: - return False + if self.pool.get('ir.attachment').search_count(cr,uid,[('url','like','https://docs.google.com/document%'),('res_model','=',model),('res_id','=',ids[0])]) !=0: + return False else: - return self.search(cr, uid, domain) - + return True config() -- cgit v1.2.3 From 515af1d3d988af70a833a22ada9edce49dd3c351 Mon Sep 17 00:00:00 2001 From: MVA Date: Tue, 3 Apr 2012 09:07:52 +0200 Subject: [IMP] change the domain to enable spreadsheet and reindentation in the js file bzr revid: mva@openerp.com-20120403070752-4gfw1hg3p6ifzmwi --- addons/google_docs/google_docs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'addons/google_docs/google_docs.py') diff --git a/addons/google_docs/google_docs.py b/addons/google_docs/google_docs.py index e195fcf21a6..5a6d33e9725 100644 --- a/addons/google_docs/google_docs.py +++ b/addons/google_docs/google_docs.py @@ -139,7 +139,7 @@ class config(osv.osv): Method use with the js to hidde or show the add google doc button @return : list of configuration ids or false ''' - if self.pool.get('ir.attachment').search_count(cr,uid,[('url','like','https://docs.google.com/document%'),('res_model','=',model),('res_id','=',ids[0])]) !=0: + if self.pool.get('ir.attachment').search_count(cr,uid,[('url','like','https://docs.google.com/%'),('res_model','=',model),('res_id','=',ids[0])]) !=0: return False else: return True -- cgit v1.2.3 From ab372e3dcf79744856ee658a0a4107b6cec7395c Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Wed, 23 May 2012 11:51:36 +0200 Subject: [IMP] google_docs: reviewed code. Overall cleaning of methods, better documentation, refactoring, fix of some glitches and so on... bzr revid: qdp-launchpad@openerp.com-20120523095136-vj1n9ekukdxibzr2 --- addons/google_docs/google_docs.py | 134 ++++++++++++++++++++------------------ 1 file changed, 69 insertions(+), 65 deletions(-) (limited to 'addons/google_docs/google_docs.py') diff --git a/addons/google_docs/google_docs.py b/addons/google_docs/google_docs.py index 5a6d33e9725..1eeb8d2fff2 100644 --- a/addons/google_docs/google_docs.py +++ b/addons/google_docs/google_docs.py @@ -19,6 +19,7 @@ ############################################################################## from osv import osv, fields +from tools.translate import _ try: import gdata.docs.data import gdata.docs.client @@ -31,95 +32,102 @@ except ImportError: class google_docs_ir_attachment(osv.osv): _inherit = 'ir.attachment' - def _auth(self, cr, uid,context=None): + def _auth(self, cr, uid, context=None): ''' Connexion with google base account @return client object for connexion ''' #pool the google.login in google_base_account google_pool = self.pool.get('google.login') - - #get gmail password and login - user_config = google_pool.default_get( cr, uid, {'user' : '' , 'password' : ''},context=context) + #get gmail password and login. We use default_get() instead of a create() followed by a read() on the + # google.login object, because it is easier. The keys 'user' and 'password' ahve to be passed in the dict + # but the values will be replaced by the user gmail password and login. + user_config = google_pool.default_get( cr, uid, {'user' : '' , 'password' : ''}, context=context) #login gmail account client = google_pool.google_login( user_config['user'], user_config['password'], type='docs_client', context=context) if not client: - raise osv.except_osv(('Google Docs Error!'),("Check your google configuration in users/synchronization") ) + raise osv.except_osv( _('Google Docs Error!'), _("Check your google configuration in users/synchronization")) return client - def create_empty_google_doc(self, cr, uid, name_gdocs, 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. - @param model: the current model name. - @param type_doc: text, spreadsheet or slide. - @return the document object. - @return False if the google_base_account hasn't been configured yet. + def create_empty_google_doc(self, cr, uid, res_model, res_id, context=None): + '''Create a new google document, empty and with a default type (txt) + :param res_model: the object for which the google doc is created + :param res_id: the Id of the object for which the google doc is created + :return: the ID of the google document object created ''' #login with the base account google module - client = self._auth(cr, uid,context=context) + client = self._auth(cr, uid, context=context) # create the document in google docs local_resource = gdata.docs.data.Resource(gdata.docs.data.DOCUMENT_LABEL) #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 + # create an ir.attachment into the db self.create(cr, uid, { - 'res_model': model, - 'res_id': ids[0], + 'res_model': res_model, + 'res_id': res_id, 'type': 'url', - 'name': 'Google Doc', + 'name': _('Google Doc'), 'url': gdocs_resource.get_alternate_link().href, - },context=context) - - - return 1 + }, context=context) + return gdocs_resource.resource_id.text - def copy_gdoc(self, cr, uid, name_gdocs, model, google_res_id, ids,context=None): + def copy_gdoc(self, cr, uid, res_model, res_id, name_gdocs, gdoc_template_id, context=None): ''' copy an existing document in google docs + :param res_model: the object for which the google doc is created + :param res_id: the Id of the object for which the google doc is created + :param name_gdocs: the name of the future ir.attachment that will be created. Based on the google doc template foun. + :param gdoc_template_id: the id of the google doc document to copy + :return: the ID of the google document object created ''' + #login with the base account google module client = self._auth(cr, uid) # fetch and copy the original document try: - original_resource = client.get_resource_by_id(google_res_id) + original_resource = client.get_resource_by_id(gdoc_template_id) #copy the document you choose in the configuration - copy_resource = client.copy_resource(original_resource,'copy_%s' % original_resource.title.text) + copy_resource = client.copy_resource(original_resource, 'copy_%s' % original_resource.title.text) except: - raise osv.except_osv(('Google Docs Error!'),("Your ressource id is not correct. You can find the id in the google docs URL") ) - # register into the db + raise osv.except_osv(_('Google Docs Error!'), _("Your resource id is not correct. You can find the id in the google docs URL")) + # create an ir.attachment self.create(cr, uid, { - 'res_model': model, - 'res_id': ids[0], + 'res_model': res_model, + 'res_id': res_id, 'type': 'url', 'name': name_gdocs, 'url': copy_resource.get_alternate_link().href - },context=context) - - return copy_resource + }, context=context) + return copy_resource.resource_id.text -class google_docs(osv.osv): - _name = 'google.docs' - - def doc_get(self, cr, uid, model, id, type_doc,context=None): - ir_attachment_ref = self.pool.get('ir.attachment') + def google_doc_get(self, cr, uid, res_model, ids, context=None): + ''' + Function called by the js, when no google doc are yet associated with a record, with the aim to create one. It + will first seek for a google.docs.config associated with the model `res_model` to find out what's the template + of google doc to copy (this is usefull if you want to start with a non-empty document, a type or a name + different than the default values). If no config is associated with the `res_model`, then a blank text document + with a default name is created. + :param res_model: the object for which the google doc is created + :param ids: the list of ids of the objects for which the google doc is created. This list is supposed to have + a length of 1 element only (batch processing is not supported in the code, though nothing really prevent it) + :return: the google document object created + ''' + assert len(ids) == 1, 'Creating google docs may only be done by one at a time' + res_id = ids[0] + pool_ir_attachment = self.pool.get('ir.attachment') pool_gdoc_config = self.pool.get('google.docs.config') - google_docs_config = pool_gdoc_config.search(cr, uid, [('model_id', '=', model)]) - name_gdocs='' - model_fields_dic = self.pool.get(model).read(cr,uid,id,[]) - - if google_docs_config: - name_gdocs = pool_gdoc_config.browse(cr,uid,google_docs_config,context=context)[0].name_template - name_gdocs = name_gdocs % model_fields_dic[0] - - # check if a model is configurate with a template + name_gdocs = '' + model_fields_dic = self.pool.get(res_model).read(cr, uid, res_id, [], context=context) + + # check if a model is configured with a template + google_docs_config = pool_gdoc_config.search(cr, uid, [('model_id', '=', res_model)], context=context) if google_docs_config: - for google_config in self.pool.get('google.docs.config').browse(cr,uid,google_docs_config,context=context): - google_res_id = google_config.gdocs_resource_id - google_document = ir_attachment_ref.copy_gdoc(cr, uid,name_gdocs ,model,google_res_id, id) + name_gdocs = pool_gdoc_config.browse(cr, uid, google_docs_config, context=context)[0].name_template + name_gdocs = name_gdocs % model_fields_dic + google_template_id = pool_gdoc_config.browse(cr, uid, google_docs_config[0], context=context).gdocs_resource_id + google_document = pool_ir_attachment.copy_gdoc(cr, uid, res_model, res_id, name_gdocs, google_template_id, context=context) else: - google_document = ir_attachment_ref.create_empty_google_doc(cr, uid,name_gdocs, model, id, type_doc) - return -1 - + google_document = pool_ir_attachment.create_empty_google_doc(cr, uid, res_model, res_id, context=context) + return google_document class config(osv.osv): _name = 'google.docs.config' @@ -127,22 +135,18 @@ class config(osv.osv): _columns = { 'model_id': fields.many2one('ir.model', 'Model'), - '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'), + 'gdocs_resource_id': fields.char('Google resource ID', size=64,help=''' +This is the id of the template document, on google side. You can find thanks to its URL: +*for a text document with url like `https://docs.google.com/a/openerp.com/document/d/123456789/edit`, the ID is `document:123456789` +*for a spreadsheet document with url like `https://docs.google.com/a/openerp.com/spreadsheet/ccc?key=123456789#gid=0`, the ID is `spreadsheet:123456789` +*for a presentation (slide show) document with url like `https://docs.google.com/a/openerp.com/presentation/d/123456789/edit#slide=id.p`, the ID is `presentation:123456789` +*for a drawing document with url like `https://docs.google.com/a/openerp.com/drawings/d/123456789/edit`, the ID is `drawings:123456789` +... +'''), 'name_template': fields.char('GDoc name template ', size=64, help='This is the name which appears on google side'), } _defaults = { - 'name_template': 'pr_%(name)s', + 'name_template': 'gdoc_%(name)s', } - def get_config(self, cr, uid, ids, model,context=None): - ''' - Method use with the js to hidde or show the add google doc button - @return : list of configuration ids or false - ''' - if self.pool.get('ir.attachment').search_count(cr,uid,[('url','like','https://docs.google.com/%'),('res_model','=',model),('res_id','=',ids[0])]) !=0: - return False - else: - return True config() - - -- cgit v1.2.3 From 90bc5b9b329924a38fe559e73d79daaface03426 Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Wed, 23 May 2012 13:02:15 +0200 Subject: [FIX] google_docs: typo in help tooltip bzr revid: qdp-launchpad@openerp.com-20120523110215-5ek6vz6pa188r4do --- addons/google_docs/google_docs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'addons/google_docs/google_docs.py') diff --git a/addons/google_docs/google_docs.py b/addons/google_docs/google_docs.py index 1eeb8d2fff2..659c86ad0d1 100644 --- a/addons/google_docs/google_docs.py +++ b/addons/google_docs/google_docs.py @@ -136,7 +136,7 @@ class config(osv.osv): _columns = { 'model_id': fields.many2one('ir.model', 'Model'), 'gdocs_resource_id': fields.char('Google resource ID', size=64,help=''' -This is the id of the template document, on google side. You can find thanks to its URL: +This is the id of the template document, on google side. You can find it thanks to its URL: *for a text document with url like `https://docs.google.com/a/openerp.com/document/d/123456789/edit`, the ID is `document:123456789` *for a spreadsheet document with url like `https://docs.google.com/a/openerp.com/spreadsheet/ccc?key=123456789#gid=0`, the ID is `spreadsheet:123456789` *for a presentation (slide show) document with url like `https://docs.google.com/a/openerp.com/presentation/d/123456789/edit#slide=id.p`, the ID is `presentation:123456789` -- cgit v1.2.3