No activity today, make something!
tiddlyweb Retrieving Tiddlers From Store

20160313160700 cdent  

If writing plugin code to handle a web request, you can use code like the below to retrieve a tiddler from the store. The Server Request Model establishes a store reference named in the environ.

from tiddlyweb.model.tiddler import Tiddler

store = environ['']

tiddler = Tiddler(title, bag)
tiddler.revision = revision # N.B.: only set if a specific revision is desired
tiddler = store.get(tiddler)

When the code is not initiated by a web request, the caller must establish the store.

from import Store
from tiddlyweb.config import config

store = Store(config['server_store'][0], config['server_store'][1], environ={})
store = Store(config['server_store'][0], config['server_store'][1], environ={'tiddlyweb.config': config})

Retrieving Tiddlers From Bag or Recipe

from tiddlyweb.model.bag import Bag
from tiddlyweb.model.recipe import Recipe
from import Store
from tiddlyweb import control
from tiddlyweb.config import config

# set up environment
env = { 'tiddlyweb.config': config }
store = Store(config['server_store'][0], env)

# retrieve tiddlers from bag
bag_name = 'foo'
bag = Bag(bag_name)
bag = store.get(bag)
tiddlers = store.list_bag_tiddlers(bag)

# retrieve tiddlers from recipe
recipe_name = 'bar'
recipe = Recipe(recipe_name)
recipe = store.get(recipe)
tiddlers = control.get_tiddlers_from_recipe(recipe, env)

# In both the above cases the tiddlers returns have not been populated with data
# from the store. To do that do this:
for tiddler in tiddlers:
    tiddler = store.get(tiddler)
    # do something with the tiddler