From 836ea16603ffdb9d66b1710c3a3722bfc987fce2 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Mon, 4 Nov 2013 10:20:51 -0500 Subject: [PATCH] Add links for self and collection as appropriate --- confluent/httpapi.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/confluent/httpapi.py b/confluent/httpapi.py index cb9d6d4d..4d64a093 100644 --- a/confluent/httpapi.py +++ b/confluent/httpapi.py @@ -256,10 +256,22 @@ def _assemble_html(responses, resource, querydict): yield 'respective values honored by the confluent server.
' yield '' yield '' + yield '%s
' % (resource, resource) + if resource[-1] == '/': + yield '../
' + else: + yield './
' + pendingrsp = [] for rsp in responses: + if isinstance(rsp, confluent.messages.LinkRelation): + yield rsp.html() + yield "
" + else: + pendingrsp.append(rsp) + for rsp in pendingrsp: yield rsp.html() yield "
" - yield '' + yield '' def _assemble_json(responses, resource): @@ -271,8 +283,11 @@ def _assemble_json(responses, resource): docomma = False links = { 'self': ['{"href":"%s"}' % resource], - 'collection': ['{"href":"%s"}' % '../'], } + if resource[-1] == '/': + links['collection'] = ['{"href":"%s"}' % '../'] + else: + links['collection'] = ['{"href":"%s"}' % './'] yield '{' hadrsp = False for rsp in responses: