def determine_tiddler_bag_from_recipe(recipe, tiddler, environ=None): """ We have a recipe and a tiddler. We need to know the bag in which this tiddler can be found. This is different from determine_bag_for_tiddler(). That one finds the bag the tiddler _could_ be in. This is the bag the tiddler _is_ in. We reverse the recipe_list, and filter each bag according to the rule. Then we look in the list of tiddlers and see if ours is in there. """ store = recipe.store template = _recipe_template(environ) for bag, filter_string in reversed(recipe.get_recipe(template)): if isinstance(bag, basestring): bag = Bag(name=bag) if store: bag = store.get(bag) # If there is a filter_string then we need to load the tiddlers off # the store. If there's not, then we can just use the list that is # already in the bag, saving a bit of time. if filter_string: for candidate_tiddler in filter_tiddlers_from_bag(bag, filter_string): if tiddler.title == candidate_tiddler.title: return bag else: for candidate_tiddler in bag.gen_tiddlers(): if tiddler.title == candidate_tiddler.title: return bag raise NoBagError('no suitable bag for %s' % tiddler.title)
def retrieve_from_store(email): """ get the tiddler requested by the email from the store and return it as an email """ store = get_store(config) tiddler_title = clean_subject(email["subject"]) tiddler = Tiddler(tiddler_title) bag = determine_bag(email["to"]) tiddler.bag = bag try: tiddler = store.get(tiddler) response_text = tiddler.text except NoTiddlerError: # Tiddler not found. Return a list of all tiddlers bag = Bag(bag) bag = store.get(bag) response_text = "The following tiddlers are in %s:\n" % email["to"].split("@")[1] tiddlers = bag.gen_tiddlers() tiddlers = [tiddler for tiddler in tiddlers] response_text += "\n".join([tiddler.title for tiddler in tiddlers]) response_email = {"from": email["to"], "to": email["from"], "subject": tiddler.title, "body": response_text} return response_email
def check_bag(tiddler, store, bag_names): """ check that the tiddler is not in the listed bags """ for bag_name in bag_names: bag = Bag(bag_name) bag = store.get(bag) tiddlers = bag.gen_tiddlers() if tiddler.title in [reserved.title for reserved in tiddlers]: raise InvalidTiddlerError('Tiddler name is reserved: %s' \ % tiddler.title)