def list_spaces(environ, start_response): """ List all the spaces on the service, as a JSON list. If a "mine" parameter is present, just get the current user's spaces. """ store = environ['tiddlyweb.store'] mine = environ['tiddlyweb.query'].get('mine', [None])[0] current_user = environ['tiddlyweb.usersign']['name'] if mine: spaces = [] try: recipe_names = store.storage.cached_storage.user_spaces( current_user) except AttributeError: recipe_names = store.storage.user_spaces(current_user) for recipe in recipe_names: spaces.append(Space.name_from_recipe(recipe)) else: spaces = [ Space.name_from_recipe(recipe.name) for recipe in store.list_recipes() if Space.recipe_is_public(recipe.name) ] start_response('200 OK', [('Cache-Control', 'no-cache'), ('Content-Type', 'application/json; charset=UTF-8')]) return simplejson.dumps([{ 'name': space, 'uri': space_uri(environ, space) } for space in sorted(spaces)])
def list_spaces(environ, start_response): """ List all the spaces on the service, as a JSON list. If a "mine" parameter is present, just get the current user's spaces. """ store = environ['tiddlyweb.store'] mine = environ['tiddlyweb.query'].get('mine', [None])[0] current_user = environ['tiddlyweb.usersign']['name'] if mine: spaces = [] try: recipe_names = store.storage.cached_storage.user_spaces( current_user) except AttributeError: recipe_names = store.storage.user_spaces(current_user) for recipe in recipe_names: spaces.append(Space.name_from_recipe(recipe)) else: spaces = [Space.name_from_recipe(recipe.name) for recipe in store.list_recipes() if Space.recipe_is_public(recipe.name)] start_response('200 OK', [ ('Cache-Control', 'no-cache'), ('Content-Type', 'application/json; charset=UTF-8')]) return simplejson.dumps([{'name': space, 'uri': space_uri(environ, space)} for space in sorted(spaces)])
def test_recipe_is(): assert Space.recipe_is_public('cat_public') assert not Space.recipe_is_public('cat_private') assert Space.recipe_is_private('cat_private') assert not Space.recipe_is_private('cat_public')