[IMP]google_drive: ressource_id with regex

bzr revid: dle@openerp.com-20130626150719-ry3wdngld3wfmdrt
This commit is contained in:
Denis Ledoux 2013-06-26 17:07:19 +02:00
parent afa6ea8e4f
commit fab8c0682f
2 changed files with 6 additions and 9 deletions

View File

@ -36,7 +36,7 @@ class base_config_settings(osv.osv_memory):
help="""Enable the public part of openerp, openerp becomes a public website."""), help="""Enable the public part of openerp, openerp becomes a public website."""),
'module_auth_oauth': fields.boolean('Use external authentication providers, sign in with google, facebook, ...'), 'module_auth_oauth': fields.boolean('Use external authentication providers, sign in with google, facebook, ...'),
'module_base_import': fields.boolean("Allow users to import data from CSV files"), 'module_base_import': fields.boolean("Allow users to import data from CSV files"),
'module_google_drive': fields.boolean('Attach a google document to any record', 'module_google_drive': fields.boolean('Attach Google documents to any record',
help="""This installs the module google_docs."""), help="""This installs the module google_docs."""),
} }

View File

@ -26,6 +26,7 @@ from openerp.tools.translate import _
import urllib import urllib
import urllib2 import urllib2
import json import json
import re
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
@ -130,14 +131,10 @@ class config(osv.osv):
def _resource_get(self, cr, uid, ids, name, arg, context=None): def _resource_get(self, cr, uid, ids, name, arg, context=None):
result = {} result = {}
for data in self.browse(cr, uid, ids, context): for data in self.browse(cr, uid, ids, context):
template_url = data.google_drive_template_url mo = re.search("(key=|/d/)([A-Za-z0-9-]+)", data.google_drive_template_url)
try: if mo:
if '/spreadsheet/' in template_url: result[data.id] = mo.group(2)
key = template_url.split('key=')[1] else:
else:
key = template_url.split('/d/')[1].split('/')[0]
result[data.id] = str(key)
except IndexError:
raise osv.except_osv(_('Incorrect URL!'), _("Please enter a valid Google Document URL.")) raise osv.except_osv(_('Incorrect URL!'), _("Please enter a valid Google Document URL."))
return result return result