[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."""),
'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_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."""),
}

View File

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