def bmark_get(request): """Return a bookmark requested via hash_id We need to return a nested object with parts bmark - readable """ rdict = request.matchdict params = request.params hash_id = rdict.get('hash_id', None) username = request.user.username # the hash id will always be there or the route won't match bookmark = BmarkMgr.get_by_hash(hash_id, username=username) last_bmark = {} if 'last_bmark' in params and params['last_bmark'] != "false": last = BmarkMgr.get_recent_bmark(username=username) if last is not None: last_bmark = {'last': dict(last)} if bookmark is None: request.response.status_int = 404 ret = {'error': "Bookmark for hash id {0} not found".format(hash_id)} ret.update(last_bmark) return ret else: return_obj = dict(bookmark) if 'with_content' in params and params['with_content'] != 'false': if bookmark.readable: return_obj['readable'] = dict(bookmark.readable) return_obj['tags'] = [dict(tag[1]) for tag in bookmark.tags.items()] ret = {'bmark': return_obj} ret.update(last_bmark) return ret