def test_filter_bag_by_filter(): """ Confirm a bag will properly filter. """ bagfour = Bag('bagfour') store.put(bagfour) bagfour.store = store for tiddler in tiddlers: tiddler.bag = 'bagfour' store.put(tiddler) filtered_tiddlers = list(control._filter_tiddlers_from_bag(bagfour, 'select=title:TiddlerOne', environ=environ)) assert len(filtered_tiddlers) == 1 assert filtered_tiddlers[0].title == 'TiddlerOne' filtered_tiddlers = list(control._filter_tiddlers_from_bag(bagfour, 'select=tag:tagone', environ=environ)) assert len(filtered_tiddlers) == 2 filters, thing = parse_for_filters( 'select=tag:tagone;select=title:TiddlerThree', environ=environ) filtered_tiddlers = list(control._filter_tiddlers_from_bag(bagfour, filters, environ=environ)) assert len(filtered_tiddlers) == 1 assert filtered_tiddlers[0].title == 'TiddlerThree'
def test_filter_bag_by_filter(): """ Confirm a bag will properly filter. """ bagfour = Bag('bagfour') store.put(bagfour) bagfour.store = store for tiddler in tiddlers: tiddler.bag = 'bagfour' store.put(tiddler) filtered_tiddlers = list( control._filter_tiddlers_from_bag(bagfour, 'select=title:TiddlerOne', environ=environ)) assert len(filtered_tiddlers) == 1 assert filtered_tiddlers[0].title == 'TiddlerOne' filtered_tiddlers = list( control._filter_tiddlers_from_bag(bagfour, 'select=tag:tagone', environ=environ)) assert len(filtered_tiddlers) == 2 filters, thing = parse_for_filters( 'select=tag:tagone;select=title:TiddlerThree', environ=environ) filtered_tiddlers = list( control._filter_tiddlers_from_bag(bagfour, filters, environ=environ)) assert len(filtered_tiddlers) == 1 assert filtered_tiddlers[0].title == 'TiddlerThree'
def get_tiddlers_from_recipe(recipe, environ=None): """ Return the list of tiddlers that result from processing the recipe. This list of tiddlers is unique by title with tiddlers later in the recipe taking precedence over those earlier in the recipe. The tiddlers returned are empty objects. """ template = recipe_template(environ) store = recipe.store uniquifier = {} for bag, filter_string in recipe.get_recipe(template): if isinstance(bag, basestring): bag = Bag(name=bag) bag.store = store for tiddler in _filter_tiddlers_from_bag(bag, filter_string, environ=environ): uniquifier[tiddler.title] = tiddler return uniquifier.values()