summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto López López (OpenERP) <rlo@openerp.com>2012-03-01 15:45:07 +0100
committerRoberto López López (OpenERP) <rlo@openerp.com>2012-03-01 15:45:07 +0100
commit2947f6dbb8563bfab55d457e9b1c0cc99f0fc4f0 (patch)
treecda3c3c5231f8511d1304d948c0ccd535ae724f4
parentcde742506ee92500e9cd2e4c41b041613d225442 (diff)
[imp] add middleware support for spreadsheets and presentations
bzr revid: rlo@openerp.com-20120301144507-k9kqsrdzwi0h8mf5
-rw-r--r--addons/google_docs/google_docs.py97
1 files changed, 61 insertions, 36 deletions
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