Skip to content

Commit b96521c

Browse files
committed
Added the ability to limit returned fields by GET
committer: Ralf Schlatterbeck <[email protected]>
1 parent a7a57b1 commit b96521c

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

roundup/rest.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -465,15 +465,28 @@ def get_element(self, class_name, item_id, input):
465465
)
466466

467467
class_obj = self.db.getclass(class_name)
468-
props = class_obj.properties.keys()
468+
props = None
469+
for form_field in input.value:
470+
key = form_field.name
471+
value = form_field.value
472+
if key == "fields":
473+
props = value.split(",")
474+
475+
if props is None:
476+
props = class_obj.properties.keys()
477+
469478
props.sort() # sort properties
470-
result = [
471-
(prop_name, class_obj.get(item_id, prop_name))
472-
for prop_name in props
473-
if self.db.security.hasPermission(
474-
'View', self.db.getuid(), class_name, prop_name,
475-
)
476-
]
479+
480+
try:
481+
result = [
482+
(prop_name, class_obj.get(item_id, prop_name))
483+
for prop_name in props
484+
if self.db.security.hasPermission(
485+
'View', self.db.getuid(), class_name, prop_name,
486+
)
487+
]
488+
except KeyError, msg:
489+
raise UsageError("%s field not valid" % msg)
477490
result = {
478491
'id': item_id,
479492
'type': class_name,

0 commit comments

Comments
 (0)