From 5d3c915c614b84284f88637ae77d8e0582ee798b Mon Sep 17 00:00:00 2001 From: mdipierro Date: Thu, 3 Jul 2014 12:22:55 -0500 Subject: [PATCH] added parent links --- VERSION | 2 +- gluon/contrib/hypermedia.py | 30 ++++++++++++++++++++---------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/VERSION b/VERSION index 9af8bbcc..ad7b5f73 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -Version 2.9.5-trunk+timestamp.2014.07.03.11.54.34 +Version 2.9.5-trunk+timestamp.2014.07.03.12.21.52 diff --git a/gluon/contrib/hypermedia.py b/gluon/contrib/hypermedia.py index a0cf7a85..e2cdf764 100644 --- a/gluon/contrib/hypermedia.py +++ b/gluon/contrib/hypermedia.py @@ -74,16 +74,26 @@ class Collection(object): href = URL(args=field._tablename,scheme=True)+'?%s={id}' % field.name links.append({'rel':'current','href':href,'prompt':str(field), 'type':'children'}) - fields = self.table_policy.get('fields', table.fields) - for fieldname in fields: - field = table[fieldname] - if field.type=='upload' and row[fieldname]: - href = URL('download',args=row[fieldname],scheme=True) - links.append({'rel':'current','href':href,'prompt':str(field), - 'type':'attachment'}) - # should this be supported? - for rel,build in (self.table_policy.get('links',{}).items()): - links.append({'rel':'current','href':build(row),'prompt':rel}) + if row: + fields = self.table_policy.get('fields', table.fields) + for fieldname in fields: + field = table[fieldname] + if field.type.startswith('reference '): + href = URL(args=field.type[10:],vars={'id':row[fieldname]}, + scheme=True) + links.append({'rel':'current','href':href,'prompt':str(field), + 'type':'parent'}) + + for fieldname in fields: + field = table[fieldname] + if field.type=='upload' and row[fieldname]: + href = URL('download',args=row[fieldname],scheme=True) + links.append({'rel':'current','href':href,'prompt':str(field), + 'type':'attachment'}) + + # should this be supported? + for rel,build in (self.table_policy.get('links',{}).items()): + links.append({'rel':'current','href':build(row),'prompt':rel}) # not sure return links