comparison roundup/rest.py @ 5661:b08a308c273b

Better display for Link/Multilink and content Link/Multilink are now displayed as a dictionary by default. The format is controlled by the setting of the @verbose option. With @verbose=0 we get the old behavior displaying only the id. With the default @verbose=1 we get a dictionary with the id and a link inside. With @verbose=2 or larger we get the label property in the dictionary in addition (e.g. the name of a status or the name of a file). The content property is also handled differently now. For @verbose < 2 we get a dictionary with a link property in it. The property points to the standard download link for the content (or message). For @verbose >= 2 we get the previous behavior, the content property as a possibly very large json string.
author Ralf Schlatterbeck <rsc@runtux.com>
date Fri, 22 Mar 2019 14:03:37 +0100
parents d8d2b7724292
children 5ceed592706e
comparison
equal deleted inserted replaced
5660:d8d2b7724292 5661:b08a308c273b
599 class_obj = self.db.getclass(class_name) 599 class_obj = self.db.getclass(class_name)
600 node = class_obj.getnode(item_id) 600 node = class_obj.getnode(item_id)
601 etag = calculate_etag(node, class_name, item_id) 601 etag = calculate_etag(node, class_name, item_id)
602 props = None 602 props = None
603 protected=False 603 protected=False
604 verbose=1
604 for form_field in input.value: 605 for form_field in input.value:
605 key = form_field.name 606 key = form_field.name
606 value = form_field.value 607 value = form_field.value
607 if key == "@fields": 608 if key == "@fields":
608 props = value.split(",") 609 props = value.split(",")
609 if key == "@protected": 610 if key == "@protected":
610 # allow client to request read only 611 # allow client to request read only
611 # properties like creator, activity etc. 612 # properties like creator, activity etc.
612 protected = value.lower() == "true" 613 protected = value.lower() == "true"
613 614 if key == "@verbose":
615 verbose = int (value)
616
617 result = {}
618 uid = self.db.getuid()
614 if props is None: 619 if props is None:
615 props = list(sorted(class_obj.getprops(protected=protected))) 620 props = class_obj.getprops(protected=protected)
616 621
617 try: 622 try:
618 result = [ 623 for pn in sorted(props):
619 (prop_name, node.__getattr__(prop_name)) 624 prop = props[pn]
620 for prop_name in props 625 if not self.db.security.hasPermission(
621 if self.db.security.hasPermission( 626 'View', uid, class_name, pn, item_id
622 'View', self.db.getuid(), class_name, prop_name, 627 ):
623 item_id ) 628 continue
624 ] 629 v = getattr(node, pn)
630 if isinstance (prop, (hyperdb.Link, hyperdb.Multilink)):
631 linkcls = self.db.getclass (prop.classname)
632 cp = '%s/%s/' % (self.data_path, prop.classname)
633 if verbose and v:
634 if isinstance(v, type([])):
635 r = []
636 for id in v:
637 d = dict(id = id, link = cp + id)
638 if verbose > 1:
639 label = linkcls.labelprop()
640 d [label] = linkcls.get(id, label)
641 r.append(d)
642 result[pn] = r
643 else:
644 result[pn] = dict(id = v, link = cp + v)
645 if verbose > 1:
646 label = linkcls.labelprop()
647 result[pn][label] = linkcls.get(v, label)
648 else:
649 result[pn] = v
650 elif isinstance (prop, hyperdb.String) and pn == 'content':
651 # Do not show the (possibly HUGE) content prop
652 # unless very verbose, we display the standard
653 # download link instead
654 if verbose < 2:
655 u = self.db.config.TRACKER_WEB
656 p = u + '%s%s/' % (class_name, node.id)
657 result[pn] = dict(link = p)
658 else:
659 result[pn] = v
660 else:
661 result[pn] = v
625 except KeyError as msg: 662 except KeyError as msg:
626 raise UsageError("%s field not valid" % msg) 663 raise UsageError("%s field not valid" % msg)
627 result = { 664 result = {
628 'id': item_id, 665 'id': item_id,
629 'type': class_name, 666 'type': class_name,

Roundup Issue Tracker: http://roundup-tracker.org/