diff options
| author | Stefan Rijnhart <stefan@therp.nl> | 2012-11-27 12:45:32 +0100 |
|---|---|---|
| committer | Stefan Rijnhart <stefan@therp.nl> | 2012-11-27 12:45:32 +0100 |
| commit | 96d946b1f2ab23c87b240f5a9776f357b94e07bf (patch) | |
| tree | 49c2f6c1de23bc295a656354160bf252c29061c8 /addons/google_docs/google_docs.py | |
| parent | 4aa5c6dbece8b5320c307f5872bd6ca25383b03a (diff) | |
| parent | e6d033755f897b741f09bc1ab15e355d495ea73c (diff) | |
[MRG] Merged with lp:openobject-addons rev. 8141
bzr revid: stefan@therp.nl-20121127114532-otfs7npzvow1wacs
Diffstat (limited to 'addons/google_docs/google_docs.py')
| -rw-r--r-- | addons/google_docs/google_docs.py | 39 |
1 files changed, 25 insertions, 14 deletions
diff --git a/addons/google_docs/google_docs.py b/addons/google_docs/google_docs.py index 659c86ad0d1..462c8240810 100644 --- a/addons/google_docs/google_docs.py +++ b/addons/google_docs/google_docs.py @@ -17,7 +17,8 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## - +from datetime import datetime +from tools import DEFAULT_SERVER_DATETIME_FORMAT from osv import osv, fields from tools.translate import _ try: @@ -26,8 +27,11 @@ try: from gdata.client import RequestError from gdata.docs.service import DOCUMENT_LABEL import gdata.auth + from gdata.docs.data import Resource except ImportError: - raise osv.except_osv(_('Google Docs Error!'), _('Please install gdata-python-client from http://code.google.com/p/gdata-python-client/downloads/list')) + import logging + _logger = logging.getLogger(__name__) + _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' @@ -46,7 +50,7 @@ class google_docs_ir_attachment(osv.osv): #login gmail account 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/synchronization")) + raise osv.except_osv( _('Google Docs Error!'), _("Check your google configuration in Users/Users/Synchronization tab.")) return client def create_empty_google_doc(self, cr, uid, res_model, res_id, context=None): @@ -58,7 +62,8 @@ class google_docs_ir_attachment(osv.osv): #login with the base account google module client = self._auth(cr, uid, context=context) # create the document in google docs - local_resource = gdata.docs.data.Resource(gdata.docs.data.DOCUMENT_LABEL) + title = "%s %s" % (context.get("name","Untitled Document."), datetime.today().strftime(DEFAULT_SERVER_DATETIME_FORMAT)) + local_resource = gdata.docs.data.Resource(gdata.docs.data.DOCUMENT_LABEL,title=title) #create a new doc in Google Docs gdocs_resource = client.post(entry=local_resource, uri='https://docs.google.com/feeds/default/private/full/') # create an ir.attachment into the db @@ -66,10 +71,12 @@ class google_docs_ir_attachment(osv.osv): 'res_model': res_model, 'res_id': res_id, 'type': 'url', - 'name': _('Google Doc'), + 'name': title, 'url': gdocs_resource.get_alternate_link().href, }, context=context) - return gdocs_resource.resource_id.text + return {'resource_id': gdocs_resource.resource_id.text, + 'title': title, + 'url': gdocs_resource.get_alternate_link().href} def copy_gdoc(self, cr, uid, res_model, res_id, name_gdocs, gdoc_template_id, context=None): ''' @@ -86,9 +93,9 @@ class google_docs_ir_attachment(osv.osv): try: original_resource = client.get_resource_by_id(gdoc_template_id) #copy the document you choose in the configuration - copy_resource = client.copy_resource(original_resource, 'copy_%s' % original_resource.title.text) + copy_resource = client.copy_resource(original_resource, 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")) + 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 self.create(cr, uid, { 'res_model': res_model, @@ -111,7 +118,8 @@ class google_docs_ir_attachment(osv.osv): a length of 1 element only (batch processing is not supported in the code, though nothing really prevent it) :return: the google document object created ''' - assert len(ids) == 1, 'Creating google docs may only be done by one at a time' + if len(ids) != 1: + raise osv.except_osv(_('Google Docs Error!'), _("Creating google docs may only be done by one at a time.")) res_id = ids[0] pool_ir_attachment = self.pool.get('ir.attachment') pool_gdoc_config = self.pool.get('google.docs.config') @@ -122,7 +130,10 @@ class google_docs_ir_attachment(osv.osv): google_docs_config = pool_gdoc_config.search(cr, uid, [('model_id', '=', res_model)], context=context) if google_docs_config: name_gdocs = pool_gdoc_config.browse(cr, uid, google_docs_config, context=context)[0].name_template - name_gdocs = name_gdocs % model_fields_dic + try: + name_gdocs = name_gdocs % model_fields_dic + except: + raise osv.except_osv(_('Key Error!'), _("Your Google Doc Name Pattern's key does not found in object.")) google_template_id = pool_gdoc_config.browse(cr, uid, google_docs_config[0], context=context).gdocs_resource_id google_document = pool_ir_attachment.copy_gdoc(cr, uid, res_model, res_id, name_gdocs, google_template_id, context=context) else: @@ -134,16 +145,16 @@ class config(osv.osv): _description = "Google Docs templates config" _columns = { - 'model_id': fields.many2one('ir.model', 'Model'), - 'gdocs_resource_id': fields.char('Google resource ID', size=64,help=''' + 'model_id': fields.many2one('ir.model', 'Model', required=True), + 'gdocs_resource_id': fields.char('Google Resource ID to Use as Template', size=64, help=''' This is the id of the template document, on google side. You can find it thanks to its URL: *for a text document with url like `https://docs.google.com/a/openerp.com/document/d/123456789/edit`, the ID is `document:123456789` *for a spreadsheet document with url like `https://docs.google.com/a/openerp.com/spreadsheet/ccc?key=123456789#gid=0`, the ID is `spreadsheet:123456789` *for a presentation (slide show) document with url like `https://docs.google.com/a/openerp.com/presentation/d/123456789/edit#slide=id.p`, the ID is `presentation:123456789` *for a drawing document with url like `https://docs.google.com/a/openerp.com/drawings/d/123456789/edit`, the ID is `drawings:123456789` ... -'''), - 'name_template': fields.char('GDoc name template ', size=64, help='This is the name which appears on google side'), +''', required=True), + 'name_template': fields.char('Google Doc Name Pattern', size=64, help='Choose how the new google docs will be named, on google side. Eg. gdoc_%(field_name)s', required=True), } _defaults = { |
