Skip to content

Commit 8958a85

Browse files
committed
Recognize both GET element uri and collection uri
committer: Ralf Schlatterbeck <[email protected]>
1 parent ff2ea3a commit 8958a85

File tree

1 file changed

+39
-16
lines changed

1 file changed

+39
-16
lines changed

roundup/rest.py

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,51 @@ def __init__(self, db):
1919
# TODO: database, translator and instance.actions
2020
self.db = db
2121

22-
def action_get(self, resource, input):
23-
classname, itemid = hyperdb.splitDesignator(resource)
24-
cl = self.db.getclass(classname)
25-
props = cl.properties.keys()
26-
props.sort()
27-
for p in props:
28-
if not self.db.security.hasPermission('View', self.db.getuid(),
29-
classname, p, itemid):
30-
raise Unauthorised('Permission to view %s of %s denied' %
31-
(p, resource))
32-
result = [(prop, cl.get(itemid, prop)) for prop in props]
22+
def action_get(self, resource_uri, input):
23+
# TODO: split this into collection URI and resource URI
24+
class_name = resource_uri
25+
try:
26+
class_obj = self.db.getclass(class_name)
27+
"""prop_name = class_obj.labelprop()
28+
result = [class_obj.get(item_id, prop_name)
29+
for item_id in class_obj.list()
30+
if self.db.security.hasPermission('View', self.db.getuid(),
31+
class_name, prop_name, item_id)
32+
]
33+
result = json.JSONEncoder().encode(result)"""
34+
result = [{'id': item_id}
35+
for item_id in class_obj.list()
36+
if self.db.security.hasPermission('View', self.db.getuid(),
37+
class_name, None, item_id)
38+
]
39+
result = json.JSONEncoder().encode(result)
40+
#result = `len(dict(result))` + ' ' + `len(result)`
41+
except KeyError:
42+
pass
43+
44+
try:
45+
class_name, item_id = hyperdb.splitDesignator(resource_uri)
46+
class_obj = self.db.getclass(class_name)
47+
props = class_obj.properties.keys()
48+
props.sort()
49+
result = [(prop_name, class_obj.get(item_id, prop_name))
50+
for prop_name in props
51+
if self.db.security.hasPermission('View', self.db.getuid(),
52+
class_name, prop_name, item_id)
53+
]
54+
# Note: is this a bug by having an extra indent in xmlrpc ?
55+
result = json.JSONEncoder().encode(dict(result))
56+
except hyperdb.DesignatorError:
57+
pass
3358

3459
# print type(result)
3560
# print type(dict(result))
36-
return json.JSONEncoder().encode(dict(result))
61+
return result
3762
# return json.dumps(dict(result))
3863
# return dict(result)
3964

4065
def dispatch(self, method, uri, input):
41-
print method
42-
print uri
66+
print "METHOD: " + method + " URI: " + uri
4367
print type(input)
4468
pprint.pprint(input)
4569

@@ -67,6 +91,5 @@ def dispatch(self, method, uri, input):
6791
else:
6892
pass
6993

70-
print output
71-
print len(output)
94+
print "Response Length: " + `len(output)` + " - Response Content (First 50 char): " + output[:50]
7295
return output

0 commit comments

Comments
 (0)