[REF] correct the code and change the view files
bzr revid: mva@openerp.com-20120319103132-av7c09avg4p0xgt3
This commit is contained in:
parent
ebb97da4d1
commit
9d5db695ee
|
@ -4,9 +4,6 @@
|
|||
'author': 'OpenERP SA',
|
||||
'website': 'http://openerp.com',
|
||||
'category': 'Tools',
|
||||
''' 'data': [
|
||||
'google_docs.xml'
|
||||
],'''
|
||||
'installable': True,
|
||||
'auto_install': False,
|
||||
'web': True,
|
||||
|
|
|
@ -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,20 +107,17 @@ 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)
|
||||
|
||||
print google_docs_config
|
||||
|
||||
if not google_docs_config:
|
||||
else:
|
||||
google_document = ir_attachment_ref.create_empty_google_doc(cr, uid, model, id, type_doc)
|
||||
return -1
|
||||
|
||||
|
||||
|
||||
class config(osv.osv):
|
||||
_name = 'google.docs.config'
|
||||
_description = "Google Docs templates 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)]
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
<!-- add google docs config field in user form -->
|
||||
|
||||
<record model="ir.ui.view" id="view_google_docs_users_config_inherited_form">
|
||||
<field name="name">res.user.google_docs.config.inherited</field>
|
||||
<field name="model">res.users</field>
|
||||
<field name="inherit_id" ref="base.view_users_form" />
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<field name="signature" position="after">
|
||||
<group colspan='4'>
|
||||
<separator string='Google Docs Config' colspan='4'/>
|
||||
<field name="context_model_id"/>
|
||||
<field name='context_gdocs_resource_id'/>
|
||||
<field name='context_name'/>
|
||||
<field name='context_name_template'/>
|
||||
</group>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
</data>
|
||||
</openerp>
|
|
@ -4,25 +4,41 @@
|
|||
|
||||
<!-- add google docs config field in user form -->
|
||||
|
||||
<record model="ir.ui.view" id="view_google_docs_model_config_form">
|
||||
<field name="name">google_docs.config.form</field>
|
||||
<record model="ir.ui.view" id="view_google_docs_model_config_tree">
|
||||
<field name="name">google_docs.config.tree</field>
|
||||
<field name="model">google.docs.config</field>
|
||||
<field name="type">tree</field>
|
||||
<field name="arch" type="xml">
|
||||
<group name="default_filters" position="inside">
|
||||
<field name="context_model_id" completion="1"
|
||||
readonly="0"/>
|
||||
<field name="context_model_id"/>
|
||||
</group>
|
||||
</field>
|
||||
</record>
|
||||
<record model='ir.actions.act_window' id='action_google_docs_users_config_inherited_form'>
|
||||
|
||||
<record model="ir.ui.view" id="view_google_docs_users_config_inherited_form">
|
||||
<field name="name">google_docs.config.form</field>
|
||||
<field name="model">google.docs.config</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<group colspan='4'>
|
||||
<field name="context_model_id"/>
|
||||
<field name='context_gdocs_resource_id'/>
|
||||
<field name='context_name'/>
|
||||
<field name='context_name_template'/>
|
||||
</group>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
|
||||
<record model='ir.actions.act_window' id='action_google_docs_users_config'>
|
||||
<field name='name'>Models configuration</field>
|
||||
<field name='res_model'>google.docs.config</field>
|
||||
<field name='type'>ir.actions.act_window</field>
|
||||
<field name='view_type'>form</field>
|
||||
<field name='view_id' ref='view_google_docs_model_config_form'/>
|
||||
<field name='view_id' ref='view_google_docs_model_config_tree'/>
|
||||
</record>
|
||||
<menuitem name='Google Docs configuration' id='menu_gdocs_config' parent='base.menu_administration'/>
|
||||
<menuitem name='Models configuration' id='menu_gdocs_model_config' parent='menu_gdocs_config' action='action_google_docs_users_config_inherited_form'/>
|
||||
<menuitem name='Models configuration' id='menu_gdocs_model_config' parent='menu_gdocs_config' action='action_google_docs_users_config'/>
|
||||
</data>
|
||||
</openerp>
|
||||
|
|
|
@ -4,6 +4,7 @@ openerp.google_docs = function(instance, session) {
|
|||
instance.web.form.SidebarAttachments = instance.web.form.SidebarAttachments.extend({
|
||||
init: function() {
|
||||
this._super.apply(this, arguments);
|
||||
this.$element.delegate('.oe_google_docs_text_button', 'click', this.on_add_text_gdoc);
|
||||
var self = this;
|
||||
var config = new instance.web.DataSet(this, 'google.docs.config', this.view.dataset.get_context());
|
||||
config.call('get_config', [this.view.dataset.ids[this.view.dataset.index]], function(r) {
|
||||
|
@ -21,7 +22,7 @@ openerp.google_docs = function(instance, session) {
|
|||
});
|
||||
});
|
||||
},
|
||||
on_add_gdoc: function() {
|
||||
on_add_text_gdoc: function() {
|
||||
var self = this;
|
||||
var $gdocbtn = this.$element.find('.oe_google_docs_text_button');
|
||||
$gdocbtn.attr('disabled', 'true').find('img, span').toggle();
|
||||
|
|
|
@ -4,13 +4,6 @@
|
|||
<templates id="template" xml:space="preserve">
|
||||
<t t-extend="FormView.sidebar.attachments">
|
||||
<t t-jquery="div.oe-binary-file-set" t-operation="append">
|
||||
<br/>
|
||||
<br/>
|
||||
<br/>
|
||||
<br/>
|
||||
<br/>
|
||||
<br/>
|
||||
<br/>
|
||||
<button class="oe_google_docs_text_button" type="button">
|
||||
<img src="/web/static/src/img/throbber.gif" width="16" height="16" style="display: none"/>
|
||||
<span>Add GDoc - text</span>
|
||||
|
@ -19,10 +12,11 @@
|
|||
<img src="/web/static/src/img/throbber.gif" width="16" height="16" style="display: none"/>
|
||||
<span>Add GDoc - spreadsheet</span>
|
||||
</button>
|
||||
<!--
|
||||
<button class="oe_google_docs_slide_button" type="button">
|
||||
<img src="/web/static/src/img/throbber.gif" width="16" height="16" style="display: none"/>
|
||||
<span>Add GDoc - presentation</span>
|
||||
</button>
|
||||
</button>-->
|
||||
</t>
|
||||
</t>
|
||||
</templates>
|
||||
|
|
Loading…
Reference in New Issue