Skip to content

Commit 4207fc8

Browse files
committed
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.
1 parent 846e1c9 commit 4207fc8

File tree

1 file changed

+45
-8
lines changed

1 file changed

+45
-8
lines changed

roundup/rest.py

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,7 @@ def get_element(self, class_name, item_id, input):
601601
etag = calculate_etag(node, class_name, item_id)
602602
props = None
603603
protected=False
604+
verbose=1
604605
for form_field in input.value:
605606
key = form_field.name
606607
value = form_field.value
@@ -610,18 +611,54 @@ def get_element(self, class_name, item_id, input):
610611
# allow client to request read only
611612
# properties like creator, activity etc.
612613
protected = value.lower() == "true"
614+
if key == "@verbose":
615+
verbose = int (value)
613616

617+
result = {}
618+
uid = self.db.getuid()
614619
if props is None:
615-
props = list(sorted(class_obj.getprops(protected=protected)))
620+
props = class_obj.getprops(protected=protected)
616621

617622
try:
618-
result = [
619-
(prop_name, node.__getattr__(prop_name))
620-
for prop_name in props
621-
if self.db.security.hasPermission(
622-
'View', self.db.getuid(), class_name, prop_name,
623-
item_id )
624-
]
623+
for pn in sorted(props):
624+
prop = props[pn]
625+
if not self.db.security.hasPermission(
626+
'View', uid, class_name, pn, item_id
627+
):
628+
continue
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
625662
except KeyError as msg:
626663
raise UsageError("%s field not valid" % msg)
627664
result = {

0 commit comments

Comments
 (0)