From 263932ed2b92e2f18a7d928d621d5cccdbd66f37 Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Fri, 1 Feb 2013 12:51:53 +0100 Subject: [FIX] google_docs: attempt to support the various API changes in the gdata 2.0.x series The gdata guys are insane. lp bug: https://launchpad.net/bugs/1084509 fixed bzr revid: odo@openerp.com-20130201115153-jhwu0g341vgmjkxa --- addons/google_docs/google_docs.py | 46 +++++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 9 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 4b98798c832..cdb14de1de3 100644 --- a/addons/google_docs/google_docs.py +++ b/addons/google_docs/google_docs.py @@ -29,13 +29,40 @@ _logger = logging.getLogger(__name__) try: import gdata.docs.data import gdata.docs.client - from gdata.client import RequestError - from gdata.docs.service import DOCUMENT_LABEL - import gdata.auth - from gdata.docs.data import Resource + + # API breakage madness in the gdata API - those guys are insane. + try: + # gdata 2.0.15+ + gdata.docs.client.DocsClient.copy_resource + except AttributeError: + # gdata 2.0.14- : copy_resource() was copy() + gdata.docs.client.DocsClient.copy_resource = gdata.docs.client.DocsClient.copy + + try: + # gdata 2.0.16+ + gdata.docs.client.DocsClient.get_resource_by_id + except AttributeError: + try: + # gdata 2.0.15+ + gdata.docs.client.DocsClient.get_resource_by_self_link + def get_resource_by_id_2_0_16(self, resource_id, **kwargs): + return self.GetResourceBySelfLink( + gdata.docs.client.RESOURCE_FEED_URI + ('/%s' % resource_id), **kwargs) + gdata.docs.client.DocsClient.get_resource_by_id = get_resource_by_id_2_0_16 + except AttributeError: + # gdata 2.0.14- : alias get_resource_by_id() + gdata.docs.client.DocsClient.get_resource_by_id = gdata.docs.client.DocsClient.get_doc + + try: + import atom.http_interface + _logger.info('GData lib version `%s` detected' % atom.http_interface.USER_AGENT) + except (ImportError, AttributeError): + _logger.debug('GData lib version could not be detected', exc_info=True) + except ImportError: _logger.warning("Please install latest gdata-python-client from http://code.google.com/p/gdata-python-client/downloads/list") + class google_docs_ir_attachment(osv.osv): _inherit = 'ir.attachment' @@ -49,11 +76,12 @@ class google_docs_ir_attachment(osv.osv): #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) + 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) + 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/Users/Synchronization tab.")) + raise osv.except_osv(_('Google Docs Error!'), _("Check your google configuration in Users/Users/Synchronization tab.")) + _logger.info('Logged into google docs as %s', user_config['user']) return client def create_empty_google_doc(self, cr, uid, res_model, res_id, context=None): @@ -94,9 +122,9 @@ class google_docs_ir_attachment(osv.osv): client = self._auth(cr, uid) # fetch and copy the original document try: - doc = client.GetDoc(gdoc_template_id) + doc = client.get_resource_by_id(gdoc_template_id) #copy the document you choose in the configuration - copy_resource = client.copy(doc, name_gdocs) + copy_resource = client.copy_resource(doc, name_gdocs) except: 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 -- cgit v1.2.3 From 96ad6088540cc4cea5ea656f9350623cfecbc4a5 Mon Sep 17 00:00:00 2001 From: Raphael Collet Date: Fri, 29 Mar 2013 15:37:20 +0100 Subject: [IMP] general: use registry[X] instead registry.get(X) when X is dynamic bzr revid: rco@openerp.com-20130329143720-80pkd4csemlk1aqz --- 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 cdb14de1de3..3b060e199c0 100644 --- a/addons/google_docs/google_docs.py +++ b/addons/google_docs/google_docs.py @@ -155,7 +155,7 @@ class google_docs_ir_attachment(osv.osv): pool_ir_attachment = self.pool.get('ir.attachment') pool_gdoc_config = self.pool.get('google.docs.config') name_gdocs = '' - model_fields_dic = self.pool.get(res_model).read(cr, uid, res_id, [], context=context) + model_fields_dic = self.pool[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) -- cgit v1.2.3 From e69326ee3b32bf50805bf1aca73d941a3bbcd2fe Mon Sep 17 00:00:00 2001 From: Vo Minh Thu Date: Mon, 15 Apr 2013 12:23:49 +0200 Subject: [REF] removed explicit model instanciations. bzr revid: vmt@openerp.com-20130415102349-vgcrfok2k5y10cwz --- addons/google_docs/google_docs.py | 1 - 1 file changed, 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 3b060e199c0..2fd1976ae3b 100644 --- a/addons/google_docs/google_docs.py +++ b/addons/google_docs/google_docs.py @@ -191,4 +191,3 @@ This is the id of the template document, on google side. You can find it thanks _defaults = { 'name_template': 'gdoc_%(name)s', } -config() -- cgit v1.2.3