Mercurial > p > roundup > code
diff roundup/rest.py @ 5677:1fa59181ce58
Add support for @verbose=2 to a GET on a collection object. Using this
will return the label prop for each item returned by the get. Also
added an example of using this to doc/rest.txt.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Tue, 26 Mar 2019 23:29:35 -0400 |
| parents | 6dc4dba1c225 |
| children | b8e8b1b3ec77 |
line wrap: on
line diff
--- a/roundup/rest.py Tue Mar 26 17:31:28 2019 -0400 +++ b/roundup/rest.py Tue Mar 26 23:29:35 2019 -0400 @@ -490,8 +490,11 @@ """ if class_name not in self.db.classes: raise NotFound('Class %s not found' % class_name) + + uid = self.db.getuid() + if not self.db.security.hasPermission( - 'View', self.db.getuid(), class_name + 'View', uid, class_name ): raise Unauthorised('Permission to view %s denied' % class_name) @@ -504,7 +507,7 @@ 'size': None, 'index': 1 # setting just size starts at page 1 } - uid = self.db.getuid() + verbose = 1 for form_field in input.value: key = form_field.name value = form_field.value @@ -512,6 +515,8 @@ key = key[6:] value = int(value) page[key] = value + elif key == "@verbose": + verbose = int (value) else: # serve the filter purpose prop = class_obj.getprops()[key] # We drop properties without search permission silently @@ -543,9 +548,21 @@ {'id': item_id, 'link': class_path + item_id} for item_id in obj_list if self.db.security.hasPermission( - 'View', self.db.getuid(), class_name, itemid=item_id + 'View', uid, class_name, itemid=item_id ) ] + + # add verbose elements. First identifying label. + if verbose > 1: + label = class_obj.labelprop() + for obj in result['collection']: + id = obj['id'] + if self.db.security.hasPermission( + 'View', uid, class_name, property=label, + itemid=id + ): + obj[label] = class_obj.get(id, label) + result_len = len(result['collection']) # pagination - page_index from 1...N
