Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

Commit ff4132d

Browse files
Adding mappings for <gd:resouceID>, <gd:lastViewed>, and <gd:lastModifiedBy>
1 parent 56241e8 commit ff4132d

6 files changed

Lines changed: 151 additions & 96 deletions

File tree

samples/docs/docs_example.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ def _PrintFeed(self, feed):
7070
print '\n'
7171
if not feed.entry:
7272
print 'No entries in feed.\n'
73-
print '%-18s %-12s %s' % ('TITLE', 'TYPE', 'OBJECT_ID')
73+
print '%-18s %-12s %s' % ('TITLE', 'TYPE', 'RESOURCE ID')
7474
for entry in feed.entry:
7575
print '%-18s %-12s %s' % (truncate(entry.title.text.encode('UTF-8')),
7676
entry.GetDocumentType(),
77-
entry.GetDocumentResourceId())
77+
entry.resourceId.text)
7878

7979
def _GetFileExtension(self, file_name):
8080
"""Returns the uppercase file extension for a file.
@@ -138,14 +138,14 @@ def _UploadMenu(self):
138138

139139
def _DownloadMenu(self):
140140
"""Prompts that enable a user to download a local copy of a document."""
141-
object_id = ''
142-
object_id = raw_input('Enter an object id: ')
141+
resource_id = ''
142+
resource_id = raw_input('Enter an resource id: ')
143143
file_path = ''
144144
file_path = raw_input('Save file to: ')
145145

146-
if not file_path or not object_id:
146+
if not file_path or not resource_id:
147147
return
148-
148+
149149
file_name = os.path.basename(file_path)
150150
ext = self._GetFileExtension(file_name)
151151

@@ -155,19 +155,19 @@ def _DownloadMenu(self):
155155
else:
156156
content_type = gdata.docs.service.SUPPORTED_FILETYPES[ext]
157157

158-
doc_type = object_id[:object_id.find('%3A')]
158+
doc_type = resource_id[:resource_id.find(':')]
159159

160160
# When downloading a spreadsheet, the authenicated request needs to be
161161
# sent with the spreadsheet service's auth token.
162162
if doc_type == 'spreadsheet':
163163
print 'Downloading spreadsheet to %s...' % (file_path,)
164164
docs_token = self.gd_client.GetClientLoginToken()
165165
self.gd_client.SetClientLoginToken(self.gs_client.GetClientLoginToken())
166-
self.gd_client.DownloadSpreadsheet(object_id, file_path)
166+
self.gd_client.DownloadSpreadsheet(resource_id, file_path)
167167
self.gd_client.SetClientLoginToken(docs_token)
168168
else:
169169
print 'Downloading document to %s...' % (file_path,)
170-
self.gd_client.DownloadDocument(object_id, file_path)
170+
self.gd_client.DownloadDocument(resource_id, file_path)
171171

172172
def _ListDocuments(self):
173173
"""Retrieves and displays a list of documents based on the user's choice."""
@@ -188,8 +188,8 @@ def _ListDocuments(self):
188188

189189
def _ListAclPermissions(self):
190190
"""Retrieves a list of a user's folders and displays them."""
191-
object_id = raw_input('Enter an object id: ')
192-
query = gdata.docs.service.DocumentAclQuery(object_id)
191+
resource_id = raw_input('Enter an resource id: ')
192+
query = gdata.docs.service.DocumentAclQuery(resource_id)
193193
print '\nListing document permissions:'
194194
feed = self.gd_client.GetDocumentListAclFeed(query.ToUri())
195195
for acl_entry in feed.entry:
@@ -198,11 +198,11 @@ def _ListAclPermissions(self):
198198

199199
def _ModifyAclPermissions(self):
200200
"""Create or updates the ACL entry on an existing document."""
201-
object_id = raw_input('Enter an object id: ')
201+
resource_id = raw_input('Enter an resource id: ')
202202
email = raw_input('Enter an email address: ')
203203
role_value = raw_input('Enter a permission (reader/writer/owner/remove): ')
204204

205-
uri = gdata.docs.service.DocumentAclQuery(object_id).ToUri()
205+
uri = gdata.docs.service.DocumentAclQuery(resource_id).ToUri()
206206
acl_feed = self.gd_client.GetDocumentListAclFeed(uri)
207207

208208
found_acl_entry = None
@@ -227,7 +227,6 @@ def _ModifyAclPermissions(self):
227227
acl_entry = gdata.docs.DocumentListAclEntry(scope=scope, role=role)
228228
inserted_entry = self.gd_client.Post(
229229
acl_entry, uri, converter=gdata.docs.DocumentListAclEntryFromString)
230-
print inserted_entry
231230

232231
print '\nListing document permissions:'
233232
acl_feed = self.gd_client.GetDocumentListAclFeed(uri)
@@ -261,10 +260,10 @@ def _PrintMenu(self):
261260

262261
def _GetMenuChoice(self, max):
263262
"""Retrieves the menu selection from the user.
264-
263+
265264
Args:
266265
max: [int] The maximum number of allowed choices (inclusive)
267-
266+
268267
Returns:
269268
The integer of the menu item chosen by the user.
270269
"""
@@ -276,7 +275,7 @@ def _GetMenuChoice(self, max):
276275
except ValueError:
277276
print 'Invalid choice. Please choose a value between 1 and', max
278277
continue
279-
278+
280279
if num > max or num < 1:
281280
print 'Invalid choice. Please choose a value between 1 and', max
282281
else:

src/gdata/docs/__init__.py

Lines changed: 48 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def __init__(self, value=None, extension_elements=None,
6262

6363
class FeedLink(atom.AtomBase):
6464
"""The DocList gd:feedLink element"""
65-
65+
6666
_tag = 'feedLink'
6767
_namespace = gdata.GDATA_NAMESPACE
6868
_attributes = atom.AtomBase._attributes.copy()
@@ -76,6 +76,38 @@ def __init__(self, href=None, rel=None, text=None, extension_elements=None,
7676
atom.AtomBase.__init__(self, extension_elements=extension_elements,
7777
extension_attributes=extension_attributes, text=text)
7878

79+
80+
class ResourceId(atom.AtomBase):
81+
"""The DocList gd:resourceId element"""
82+
83+
_tag = 'resourceId'
84+
_namespace = gdata.GDATA_NAMESPACE
85+
_children = atom.AtomBase._children.copy()
86+
_attributes = atom.AtomBase._attributes.copy()
87+
_attributes['value'] = 'value'
88+
89+
def __init__(self, value=None, extension_elements=None,
90+
extension_attributes=None, text=None):
91+
self.value = value
92+
self.text = text
93+
self.extension_elements = extension_elements or []
94+
self.extension_attributes = extension_attributes or {}
95+
96+
97+
class LastModifiedBy(atom.Person):
98+
"""The DocList gd:lastModifiedBy element"""
99+
100+
_tag = 'lastModifiedBy'
101+
_namespace = gdata.GDATA_NAMESPACE
102+
103+
104+
class LastViewed(atom.Person):
105+
"""The DocList gd:lastModifiedBy element"""
106+
107+
_tag = 'lastViewed'
108+
_namespace = gdata.GDATA_NAMESPACE
109+
110+
79111
class DocumentListEntry(gdata.GDataEntry):
80112
"""The Google Documents version of an Atom Entry"""
81113

@@ -84,12 +116,22 @@ class DocumentListEntry(gdata.GDataEntry):
84116
_children = gdata.GDataEntry._children.copy()
85117
_attributes = gdata.GDataEntry._attributes.copy()
86118
_children['{%s}feedLink' % gdata.GDATA_NAMESPACE] = ('feedLink', FeedLink)
87-
88-
def __init__(self, feedLink=None, author=None, category=None, content=None,
119+
_children['{%s}resourceId' % gdata.GDATA_NAMESPACE] = ('resourceId',
120+
ResourceId)
121+
_children['{%s}lastModifiedBy' % gdata.GDATA_NAMESPACE] = ('lastModifiedBy',
122+
LastModifiedBy)
123+
_children['{%s}lastViewed' % gdata.GDATA_NAMESPACE] = ('lastViewed',
124+
LastViewed)
125+
126+
def __init__(self, resourceId=None, feedLink=None, lastViewed=None,
127+
lastModifiedBy=None, author=None, category=None, content=None,
89128
atom_id=None, link=None, published=None, title=None,
90129
updated=None, text=None, extension_elements=None,
91130
extension_attributes=None):
92-
self.feedLink = feedLink or None
131+
self.feedLink = feedLink
132+
self.lastViewed = feedLink
133+
self.lastModifiedBy = feedLink
134+
self.resourceId = feedLink
93135
gdata.GDataEntry.__init__(
94136
self, author=author, category=category, content=content,
95137
atom_id=atom_id, link=link, published=published, title=title,
@@ -121,26 +163,6 @@ def GetDocumentType(self):
121163
else:
122164
return None
123165

124-
def GetDocumentResourceId(self):
125-
"""Extracts the document/presentation/spreadsheet/folder id of document.
126-
127-
The object/resource ids are of the form document%3A123456789,
128-
folder%3A123456789, etc. This method is should be used to extract
129-
the object id for use in exporting or querying for particular
130-
documents. Note: the object id which this method returns is a part
131-
of the Atom id.
132-
133-
Returns:
134-
The document's unique id as a string.
135-
"""
136-
doc_type = self.GetDocumentType()
137-
138-
if self.id.text:
139-
match = re.search('(' + doc_type + '%3A[^\/]+)\/?.*$', self.id.text)
140-
if match:
141-
return match.group(1)
142-
return None
143-
144166

145167
def DocumentListEntryFromString(xml_string):
146168
"""Converts an XML string into a DocumentListEntry object.
@@ -156,7 +178,7 @@ def DocumentListEntryFromString(xml_string):
156178

157179
class DocumentListAclEntry(gdata.GDataEntry):
158180
"""A DocList ACL Entry flavor of an Atom Entry"""
159-
181+
160182
_tag = gdata.GDataEntry._tag
161183
_namespace = gdata.GDataEntry._namespace
162184
_children = gdata.GDataEntry._children.copy()
@@ -189,7 +211,7 @@ def DocumentListAclEntryFromString(xml_string):
189211

190212
class DocumentListFeed(gdata.GDataFeed):
191213
"""A feed containing a list of Google Documents Items"""
192-
214+
193215
_tag = gdata.GDataFeed._tag
194216
_namespace = atom.ATOM_NAMESPACE
195217
_children = gdata.GDataFeed._children.copy()

src/gdata/docs/service.py

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ def GetDocumentListAclFeed(self, uri):
246246
247247
Args:
248248
uri: string The URI of a document's Acl feed to retrieve.
249-
249+
250250
Returns:
251251
A DocumentListAclFeed object representing the ACL feed
252252
returned by the server.
@@ -324,7 +324,7 @@ def DownloadDocument(self, entry_or_resource_id, file_path):
324324
325325
Args:
326326
entry_or_resource_id: DoclistEntry or string of the document
327-
resource id to download.
327+
resource id to download.
328328
file_path: string The full path to save the file to. The export
329329
format is inferred from the the file extension.
330330
"""
@@ -334,15 +334,17 @@ def DownloadDocument(self, entry_or_resource_id, file_path):
334334
ext = match.group(1)
335335

336336
if isinstance(entry_or_resource_id, gdata.docs.DocumentListEntry):
337-
object_id = entry_or_resource_id.GetDocumentResourceId()
337+
resource_id = entry_or_resource_id.resourceId.text
338338
else:
339-
object_id = entry_or_resource_id
340-
doc_id = object_id[object_id.find('%3A') + 3:]
339+
resource_id = entry_or_resource_id
340+
341+
resource_id = resource_id.replace(':', '%3A')
342+
doc_id = resource_id[resource_id.find('%3A') + 3:]
341343

342344
export_uri = '/feeds/download/documents/Export'
343345
export_uri += '?docID=%s&exportFormat=%s' % (doc_id, ext)
344346
self._DownloadFile(export_uri, file_path)
345-
347+
346348
def DownloadPresentation(self, entry_or_resource_id, file_path):
347349
"""Downloads a presentation from the Document List.
348350
@@ -358,15 +360,17 @@ def DownloadPresentation(self, entry_or_resource_id, file_path):
358360
ext = match.group(1)
359361

360362
if isinstance(entry_or_resource_id, gdata.docs.DocumentListEntry):
361-
object_id = entry_or_resource_id.GetDocumentResourceId()
363+
resource_id = entry_or_resource_id.resourceId.text
362364
else:
363-
object_id = entry_or_resource_id
364-
doc_id = object_id[object_id.find('%3A') + 3:]
365-
365+
resource_id = entry_or_resource_id
366+
367+
resource_id = resource_id.replace(':', '%3A')
368+
doc_id = resource_id[resource_id.find('%3A') + 3:]
369+
366370
export_uri = '/feeds/download/presentations/Export'
367371
export_uri += '?docID=%s&exportFormat=%s' % (doc_id, ext)
368372
self._DownloadFile(export_uri, file_path)
369-
373+
370374
def DownloadSpreadsheet(self, entry_or_resource_id, file_path, gid=0):
371375
"""Downloads a spreadsheet from the Document List.
372376
@@ -384,11 +388,13 @@ def DownloadSpreadsheet(self, entry_or_resource_id, file_path, gid=0):
384388
ext = match.group(1)
385389

386390
if isinstance(entry_or_resource_id, gdata.docs.DocumentListEntry):
387-
object_id = entry_or_resource_id.GetDocumentResourceId()
391+
resource_id = entry_or_resource_id.resourceId.text
388392
else:
389-
object_id = entry_or_resource_id
390-
key = object_id[object_id.find('%3A') + 3:]
391-
393+
resource_id = entry_or_resource_id
394+
395+
resource_id = resource_id.replace(':', '%3A')
396+
key = resource_id[resource_id.find('%3A') + 3:]
397+
392398
export_uri = ('http://spreadsheets.google.com'
393399
'/feeds/download/spreadsheets/Export')
394400
export_uri += '?key=%s&fmcmd=%s' % (key,
@@ -399,7 +405,7 @@ def DownloadSpreadsheet(self, entry_or_resource_id, file_path, gid=0):
399405

400406
def CreateFolder(self, title, folder_or_uri=None):
401407
"""Creates a folder in the Document List feed.
402-
408+
403409
Args:
404410
title: string The title of the folder on the server after being created.
405411
folder_or_uri: DocumentListEntry or string (optional) An object with a

src/gdata/test_data.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1613,7 +1613,7 @@
16131613
</entry>"""
16141614

16151615
DOCUMENT_LIST_FEED = """<?xml version='1.0' encoding='UTF-8'?>
1616-
<ns0:feed xmlns:ns0="http://www.w3.org/2005/Atom" ><ns1:totalResults
1616+
<ns0:feed xmlns:ns0="http://www.w3.org/2005/Atom" xmlns:ns2="http://schemas.google.com/g/2005"><ns1:totalResults
16171617
xmlns:ns1="http://a9.com/-/spec/opensearchrss/1.0/">2</ns1:totalResults><ns1:startIndex
16181618
xmlns:ns1="http://a9.com/-/spec/opensearchrss/1.0/">1</ns1:startIndex><ns0:entry><ns0:content
16191619
src="http://foo.com/fm?fmcmd=102&amp;key=supercalifragilisticexpeadocious"
@@ -1629,7 +1629,13 @@
16291629
type="application/atom+xml" /><ns0:link
16301630
href="http://docs.google.com/feeds/documents/private/full/spreadsheet%3Asupercalifragilisticexpeadocious"
16311631
rel="self" type="application/atom+xml" /><ns0:title type="text">Test Spreadsheet</ns0:title><ns0:updated>2007-07-03T18:03:32.045Z</ns0:updated>
1632-
<ns2:feedLink href="http://docs.google.com/feeds/acl/private/full/spreadsheet%3Afoofoofoo" rel="http://schemas.google.com/acl/2007#accessControlList" xmlns:ns2="http://schemas.google.com/g/2005" />
1632+
<ns2:feedLink href="http://docs.google.com/feeds/acl/private/full/spreadsheet%3Afoofoofoo" rel="http://schemas.google.com/acl/2007#accessControlList"/>
1633+
<ns2:resourceId>document:dfrkj84g_3348jbxpxcd</ns2:resourceId>
1634+
<ns2:lastModifiedBy>
1635+
<ns0:name>test.user</ns0:name>
1636+
<ns0:email>[email protected]</ns0:email>
1637+
</ns2:lastModifiedBy>
1638+
<ns2:lastViewed>2009-03-05T07:48:21.493Z</ns2:lastViewed>
16331639
</ns0:entry><ns0:entry><ns0:content
16341640
src="http://docs.google.com/RawDocContents?action=fetch&amp;docID=gr00vy"
16351641
type="text/html"
@@ -1641,7 +1647,12 @@
16411647
/><ns0:link
16421648
href="http://docs.google.com/feeds/documents/private/full/document%3Agr00vy"
16431649
rel="self" type="application/atom+xml" /><ns0:title type="text">Test Document</ns0:title><ns0:updated>2007-07-03T18:02:50.338Z</ns0:updated>
1644-
<ns2:feedLink href="http://docs.google.com/feeds/acl/private/full/document%3Afoofoofoo" rel="http://schemas.google.com/acl/2007#accessControlList" xmlns:ns2="http://schemas.google.com/g/2005" />
1650+
<ns2:feedLink href="http://docs.google.com/feeds/acl/private/full/document%3Afoofoofoo" rel="http://schemas.google.com/acl/2007#accessControlList"/>
1651+
<ns2:lastModifiedBy>
1652+
<ns0:name>test.user</ns0:name>
1653+
<ns0:email>[email protected]</ns0:email>
1654+
</ns2:lastModifiedBy>
1655+
<ns2:lastViewed>2009-03-05T07:48:21.493Z</ns2:lastViewed>
16451656
</ns0:entry><ns0:id>http://docs.google.com/feeds/documents/private/full</ns0:id><ns0:link
16461657
href="http://docs.google.com" rel="alternate" type="text/html" /><ns0:link
16471658
href="http://docs.google.com/feeds/documents/private/full"
@@ -1670,6 +1681,12 @@
16701681
type="application/atom+xml" /><ns0:link
16711682
href="http://docs.google.com/feeds/documents/private/full/spreadsheet%3Asupercalifragilisticexpealidocious"
16721683
rel="self" type="application/atom+xml" /><ns0:title type="text">Test Spreadsheet</ns0:title><ns0:updated>2007-07-03T18:03:32.045Z</ns0:updated>
1684+
<ns1:resourceId>spreadsheet:supercalifragilisticexpealidocious</ns1:resourceId>
1685+
<ns1:lastModifiedBy>
1686+
<ns0:name>test.user</ns0:name>
1687+
<ns0:email>[email protected]</ns0:email>
1688+
</ns1:lastModifiedBy>
1689+
<ns1:lastViewed>2009-03-05T07:48:21.493Z</ns1:lastViewed>
16731690
</ns0:entry>
16741691
"""
16751692

0 commit comments

Comments
 (0)