def get(environ, start_response): """ Perform a search on the store. What search means and what results are returned is dependent on the search implementation (if any) in the chosen store. """ try: search_query = environ['tiddlyweb.query']['q'][0] search_query = urllib.unquote(search_query) search_query = unicode(search_query, 'utf-8') except (KeyError, IndexError): raise HTTP400('query string required') filter_string = web.filter_query_string(environ) store = environ['tiddlyweb.store'] try: tiddlers = store.search(search_query) except StoreMethodNotImplemented: raise HTTP400('Search system not implemented') usersign = environ['tiddlyweb.usersign'] # It's necessary to get the tiddler off the store # in case we are doing wiki or atom outputs of the # search. tmp_bag = Bag('tmp_bag', tmpbag=True, searchbag=True) bag_readable = {} for tiddler in tiddlers: try: if bag_readable[tiddler.bag]: tmp_bag.add_tiddler(store.get(tiddler)) except KeyError: bag = Bag(tiddler.bag) bag = store.get(bag) try: bag.policy.allows(usersign, 'read') tmp_bag.add_tiddler(store.get(tiddler)) bag_readable[tiddler.bag] = True except(ForbiddenError, UserRequiredError): bag_readable[tiddler.bag] = False if len(filter_string): tiddlers = control.filter_tiddlers_from_bag(tmp_bag, filter_string) tmp_bag = Bag('tmp_bag', tmpbag=True) tmp_bag.add_tiddlers(tiddlers) return send_tiddlers(environ, start_response, tmp_bag)
def get_tiddlers(environ, start_response): """ Get the list of tiddlers produced by this recipe. """ filter_string = web.filter_query_string(environ) usersign = environ['tiddlyweb.usersign'] store = environ['tiddlyweb.store'] recipe = _determine_recipe(environ) recipe.policy.allows(usersign, 'read') # get the tiddlers from the recipe and uniquify them try: tiddlers = control.get_tiddlers_from_recipe(recipe, environ) tmp_bag = Bag('tmp_bag1', tmpbag=True) tmp_bag.add_tiddlers(tiddlers) except NoBagError, exc: raise HTTP404('recipe %s lists an unknown bag: %s' % (recipe.name, exc))
def get_tiddlers(environ, start_response): """ Get a list representation of the tiddlers in a bag. The information sent is dependent on the serialization chosen. """ filter_string = web.filter_query_string(environ) bag_name = _determine_bag_name(environ) bag = _get_bag(environ, bag_name) usersign = environ["tiddlyweb.usersign"] # will raise exception if there are problems bag.policy.allows(usersign, "read") try: tiddlers = control.filter_tiddlers_from_bag(bag, filter_string) except FilterError, exc: raise HTTP400("malformed filter: %s" % exc)