Пример #1
0
 def create_empty_google_doc(self, cr, uid, res_model, res_id, context=None):
     """Create a new google document, empty and with a default type (txt)
        :param res_model: the object for which the google doc is created
        :param res_id: the Id of the object for which the google doc is created
        :return: the ID of the google document object created
     """
     # 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)
     # 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
     self.create(
         cr,
         uid,
         {
             "res_model": res_model,
             "res_id": res_id,
             "type": "url",
             "name": _("Google Doc"),
             "url": gdocs_resource.get_alternate_link().href,
         },
         context=context,
     )
     return gdocs_resource.resource_id.text
Пример #2
0
 def create_empty_google_doc(self,
                             cr,
                             uid,
                             res_model,
                             res_id,
                             context=None):
     '''Create a new google document, empty and with a default type (txt)
        :param res_model: the object for which the google doc is created
        :param res_id: the Id of the object for which the google doc is created
        :return: the ID of the google document object created
     '''
     #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)
     #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
     self.create(cr,
                 uid, {
                     'res_model': res_model,
                     'res_id': res_id,
                     'type': 'url',
                     'name': _('Google Doc'),
                     'url': gdocs_resource.get_alternate_link().href,
                 },
                 context=context)
     return gdocs_resource.resource_id.text
Пример #3
0
 def create_empty_google_doc(self, cr, uid, res_model, res_id, context=None):
     '''Create a new google document, empty and with a default type (txt)
        :param res_model: the object for which the google doc is created
        :param res_id: the Id of the object for which the google doc is created
        :return: the ID of the google document object created
     '''
     #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)
     #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
     self.create(cr, uid, {
         'res_model': res_model,
         'res_id': res_id,
         'type': 'url',
         'name': _('Google Doc'),
         'url': gdocs_resource.get_alternate_link().href,
     }, context=context)
     return gdocs_resource.resource_id.text
Пример #4
0
 def create_empty_google_doc(self,
                             cr,
                             uid,
                             res_model,
                             res_id,
                             context=None):
     '''Create a new google document, empty and with a default type (txt)
        :param res_model: the object for which the google doc is created
        :param res_id: the Id of the object for which the google doc is created
        :return: the ID of the google document object created
     '''
     #login with the base account google module
     client = self._auth(cr, uid, context=context)
     # create the document in google docs
     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
     self.create(cr,
                 uid, {
                     'res_model': res_model,
                     'res_id': res_id,
                     'type': 'url',
                     'name': title,
                     'url': gdocs_resource.get_alternate_link().href,
                 },
                 context=context)
     return {
         'resource_id': gdocs_resource.resource_id.text,
         'title': title,
         'url': gdocs_resource.get_alternate_link().href
     }
Пример #5
0
  def get(self, puzzle_id):
    puzzle_id = long(puzzle_id)
    puzzle = model.Puzzle.get_by_id(puzzle_id)
    # TODO(glasser): Better error handling.
    assert puzzle is not None

    access_token = LoadAccessToken()
    if access_token is None:
      self.redirect(GetOAuthTokenHandler.get_url(puzzle_id))
      return
    client = gdata.docs.client.DocsClient()
    auth_token = gdata.gauth.OAuthHmacToken(
      GDATA_SETTINGS['CONSUMER_KEY'], GDATA_SETTINGS['CONSUMER_SECRET'],
      access_token.token, access_token.token_secret,
      gdata.gauth.ACCESS_TOKEN,
      next=None, verifier=None)
    doc = client.Create(gdata.docs.data.SPREADSHEET_LABEL,
                        "%s [%s]" % (self.request.get('title'), puzzle.title),
                        auth_token=auth_token)
    match = gdata.docs.data.RESOURCE_ID_PATTERN.match(doc.resource_id.text)
    assert match
    assert match.group(1) == gdata.docs.data.SPREADSHEET_LABEL
    doc_key = match.group(3)
    acl_entry = gdata.docs.data.Acl(
      with_key=AclWithKey(key='ignored',
                          role=gdata.acl.data.AclRole(value='writer')),
      scope=gdata.acl.data.AclScope(type='default'))
    acl_entry.category.append(atom.data.Category(
      scheme=gdata.docs.data.DATA_KIND_SCHEME,
      term="http://schemas.google.com/acl/2007#accessRule"))
    acl_from_server = client.post(
      acl_entry, doc.get_acl_feed_link().href, auth_token=auth_token)
    auth_key = acl_from_server.with_key.key
    sheet = model.Spreadsheet(puzzle=puzzle, spreadsheet_key=doc_key,
                              auth_key=auth_key)
    sheet.put()
    self.redirect(PuzzleHandler.get_url(puzzle_id))
Пример #6
0
 def create_empty_google_doc(self, cr, uid, res_model, res_id, context=None):
     '''Create a new google document, empty and with a default type (txt)
        :param res_model: the object for which the google doc is created
        :param res_id: the Id of the object for which the google doc is created
        :return: the ID of the google document object created
     '''
     #login with the base account google module
     client = self._auth(cr, uid, context=context)
     # create the document in google docs
     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
     self.create(cr, uid, {
         'res_model': res_model,
         'res_id': res_id,
         'type': 'url',
         'name': title,
         'url': gdocs_resource.get_alternate_link().href,
     }, context=context)
     return {'resource_id': gdocs_resource.resource_id.text,
             'title': title,
             'url': gdocs_resource.get_alternate_link().href}