本文整理汇总了Python中tiddlyweb.model.bag.Bag.add_tiddler方法的典型用法代码示例。如果您正苦于以下问题:Python Bag.add_tiddler方法的具体用法?Python Bag.add_tiddler怎么用?Python Bag.add_tiddler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tiddlyweb.model.bag.Bag
的用法示例。
在下文中一共展示了Bag.add_tiddler方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from tiddlyweb.model.bag import Bag [as 别名]
# 或者: from tiddlyweb.model.bag.Bag import add_tiddler [as 别名]
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.
"""
store = environ['tiddlyweb.store']
tiddlers = get_tiddlers(environ)
usersign = environ['tiddlyweb.usersign']
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.skinny = True
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
return send_tiddlers(environ, start_response, tmp_bag)
示例2: tiddler_as
# 需要导入模块: from tiddlyweb.model.bag import Bag [as 别名]
# 或者: from tiddlyweb.model.bag.Bag import add_tiddler [as 别名]
def tiddler_as(self, tiddler):
"""
entry point for a single tiddler. Sets some variables
and passes the tiddler into list_tiddlers for turning
into HTML
"""
if 'tiddler' not in self.environ['tiddlyweb.recipe_template']:
self.environ['tiddlyweb.recipe_template']['tiddler'] = tiddler.title
if 'bag' not in self.environ['tiddlyweb.recipe_template']:
self.environ['tiddlyweb.recipe_template']['bag'] = tiddler.bag
if tiddler.recipe and 'recipe' not in self.environ['tiddlyweb.recipe_template']:
self.environ['tiddlyweb.recipe_template']['recipe'] = tiddler.recipe
bag = Bag('tmpbag',tmpbag=True)
bag.add_tiddler(tiddler)
self.plugin_name = self.set_plugin_name('single_tiddler')
if self.plugin_name not in self.environ['tiddlyweb.config']['tw_pages_serializers']:
content = self.pass_through_external_serializer(self.plugin_name, tiddler)
return content
self.page_title = self.environ['tiddlyweb.config']['tw_pages_serializers'][self.plugin_name]['title'] or tiddler.title
return self.list_tiddlers(bag)
示例3: tiddler_as
# 需要导入模块: from tiddlyweb.model.bag import Bag [as 别名]
# 或者: from tiddlyweb.model.bag.Bag import add_tiddler [as 别名]
def tiddler_as(self, tiddler):
logging.debug("###################################\nDOING TIDDLER_AS\n\n\n###################################")
"""
Take the single tiddler provided and inject it into
a TiddlyWiki.
"""
environ = self.environ
store = self.environ["tiddlyweb.store"]
try:
recipe_name =tiddler.recipe
tiddler_as_name = tiddler.title
resource = Recipe(recipe_name)
resource= store.get(resource)
tiddlers = control.get_tiddlers_from_recipe(resource)
bag =Bag("tmp",tmpbag=True)
logging.debug("have tiddlers %s"%tiddlers)
for a_tiddler in tiddlers:
a_tiddler.recipe = recipe_name
a_tiddler = store.get(a_tiddler)
if a_tiddler.title == "DefaultTiddlers":
a_tiddler.text = "[[%s]]"%tiddler_as_name
logging.debug("tiddler_as overriding DefaultTiddlers")
bag.add_tiddler(a_tiddler)
except AttributeError:
resource = Bag(tiddler.bag)
bag = store.get(resource)
self._prepare_twp(bag)
return self.build_non_js_version(bag,default=[tiddler])
示例4: get
# 需要导入模块: from tiddlyweb.model.bag import Bag [as 别名]
# 或者: from tiddlyweb.model.bag.Bag import add_tiddler [as 别名]
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')
filters = environ['tiddlyweb.filters']
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.skinny = True
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(filters):
tiddlers = control.filter_tiddlers_from_bag(tmp_bag, filters)
tmp_bag = Bag('tmp_bag', tmpbag=True)
tmp_bag.add_tiddlers(tiddlers)
return send_tiddlers(environ, start_response, tmp_bag)
示例5: test_list_tiddlers_as_rtf
# 需要导入模块: from tiddlyweb.model.bag import Bag [as 别名]
# 或者: from tiddlyweb.model.bag.Bag import add_tiddler [as 别名]
def test_list_tiddlers_as_rtf():
bag = Bag('test bag')
tiddlers = [Tiddler('tiddler' + str(name)) for name in xrange(2)]
[bag.add_tiddler(tiddler) for tiddler in tiddlers]
string = serializer.list_tiddlers(bag)
assert_rtf_document(string)
assert '{\\pard \\fs44 Tiddlers in Bag test bag\\par}' in string
assert ' tiddler0' in string
assert ' tiddler1' in string
示例6: _send_tiddler_revisions
# 需要导入模块: from tiddlyweb.model.bag import Bag [as 别名]
# 或者: from tiddlyweb.model.bag.Bag import add_tiddler [as 别名]
def _send_tiddler_revisions(environ, start_response, tiddler):
"""
Push the list of tiddler revisions out the network.
"""
store = environ['tiddlyweb.store']
tmp_bag = Bag('tmp', tmpbag=True, revbag=True)
try:
for revision in store.list_tiddler_revisions(tiddler):
tmp_tiddler = Tiddler(title=tiddler.title, bag=tiddler.bag)
tmp_tiddler.revision = revision
try:
tmp_tiddler = store.get(tmp_tiddler)
except NoTiddlerError, exc:
# If a particular revision is not present in the store.
raise HTTP404('tiddler %s at revision % not found, %s' %
(tiddler.title, revision, exc))
tmp_bag.add_tiddler(tmp_tiddler)
except NoTiddlerError, exc:
# If a tiddler is not present in the store.
raise HTTP404('tiddler %s not found, %s' % (tiddler.title, exc))
示例7: test_list_tiddlers_as_yaml
# 需要导入模块: from tiddlyweb.model.bag import Bag [as 别名]
# 或者: from tiddlyweb.model.bag.Bag import add_tiddler [as 别名]
def test_list_tiddlers_as_yaml():
bag = Bag('test bag')
tiddlers = [Tiddler('tiddler' + str(name)) for name in xrange(2)]
[bag.add_tiddler(tiddler) for tiddler in tiddlers]
string = serializer.list_tiddlers(bag)
assert string.startswith(u"- bag: test bag\n")
assert u"\n title: tiddler1\n" in string
assert u"\n tags: []\n" in string
o = pyyaml.load(string)
assert re.match("^\d{14}$", o[0]['modified'])
assert o[1]['tags'] == []
assert o[1]['revision'] == 0
示例8: determine_bag_for_tiddler
# 需要导入模块: from tiddlyweb.model.bag import Bag [as 别名]
# 或者: from tiddlyweb.model.bag.Bag import add_tiddler [as 别名]
def determine_bag_for_tiddler(recipe, tiddler, environ=None):
"""
Return the bag which this tiddler would be in if we
were to save it to the recipe rather than to a default
bag.
This is a matter of reversing the recipe list and seeing
if the tiddler is a part of the bag + filter. If bag+filter
is true, return that bag.
"""
template = _recipe_template(environ)
for bag, filter_string in reversed(recipe.get_recipe(template)):
# ignore the bag and make a new bag
tmpbag = Bag(filter_string, tmpbag=True)
tmpbag.add_tiddler(tiddler)
for candidate_tiddler in filter_tiddlers_from_bag(tmpbag, filter_string):
if tiddler.title == candidate_tiddler.title:
if isinstance(bag, basestring):
bag = Bag(name=bag)
return bag
raise NoBagError('no suitable bag for %s' % tiddler.title)
示例9: form
# 需要导入模块: from tiddlyweb.model.bag import Bag [as 别名]
# 或者: from tiddlyweb.model.bag.Bag import add_tiddler [as 别名]
def form(environ, start_response):
"""
Produce this named form to the web.
"""
store = environ['tiddlyweb.store']
bag_id = environ['wsgiorg.routing_args'][1]['formid']
recipe_id, uuid = bag_id.rsplit('.', 1)
logging.debug('getting form with bag %s using recipe %s' % (bag_id, recipe_id))
bag = store.get(Bag(bag_id))
_process_config_tiddler(store, bag)
recipe = store.get(Recipe(recipe_id))
base_tiddlers = control.get_tiddlers_from_recipe(recipe)
# read the bag (again) to make sure we have all the tiddlers
bag = store.get(bag)
data_tiddlers = bag.list_tiddlers()
tiddlers = base_tiddlers + data_tiddlers
tmp_bag = Bag('tmp', tmpbag=True)
for tiddler in tiddlers:
store.get(tiddler)
tmp_bag.add_tiddler(tiddler)
logging.debug(['%s:%s' % (tiddler.bag, tiddler.title) for tiddler in tmp_bag.list_tiddlers()])
environ['tiddlyweb.type'] = 'text/x-tiddlywiki'
return send_tiddlers(environ, start_response, tmp_bag)
示例10: make_basic_tw
# 需要导入模块: from tiddlyweb.model.bag import Bag [as 别名]
# 或者: from tiddlyweb.model.bag.Bag import add_tiddler [as 别名]
def make_basic_tw(self,bag):
smallerbag = Bag("tmp",tmpbag=True)
try:
skinnybags = self.environ['tiddlyweb.config']['tiddlywebwikiplus']['skinny_bags']
except KeyError:
skinnybags = []
for tiddler in bag.list_tiddlers():
if not tiddler.bag in skinnybags:
smallerbag.add_tiddler(tiddler)
else:
if "_twp_skinny_include" in tiddler.fields:
del tiddler.fields["_twp_skinny_include"]
smallerbag.add_tiddler(tiddler)
elif "root" in tiddler.fields and tiddler.fields["root"] in self.marked_tiddlers:
smallerbag.add_tiddler(tiddler)
return self._put_tiddlers_in_tiddlywiki(smallerbag.list_tiddlers())
示例11: bag
# 需要导入模块: from tiddlyweb.model.bag import Bag [as 别名]
# 或者: from tiddlyweb.model.bag.Bag import add_tiddler [as 别名]
def bag():
bag = Bag('Geekery is the Social Capital of Britain')
tiddler = Tiddler("@moo")
tiddler.fields = {u'geo.lat': u'51.52351', u'geo.long': u'-0.11046'}
bag.add_tiddler(tiddler);
tiddler = Tiddler("@lastfm")
tiddler.fields = {u'geo.lat': u'51.52762', u'geo.long': u'-0.08583'}
bag.add_tiddler(tiddler);
tiddler = Tiddler("@redmonk")
tiddler.fields = {u'geo.lat': u'', u'geo.long': u''}
bag.add_tiddler(tiddler);
tiddler = Tiddler("RSA")
tiddler.fields = {u'geo.lat': u'51.509043', u'geo.long': u'-0.12215'}
bag.add_tiddler(tiddler);
tiddler = Tiddler("Giant's Causeway")
tiddler.fields = {u'geo.lat': u'55.24083', u'geo.long': u'-6.51167'}
bag.add_tiddler(tiddler);
tiddler = Tiddler("English Channel")
tiddler.fields = {u'geo.lat': u'50.18361', u'geo.long': u'-0.53111'}
bag.add_tiddler(tiddler);
tiddler = Tiddler("River Cruises")
tiddler.fields = {u'geo.lat': u'51.50341', u'geo.long': u'-0.120527'}
bag.add_tiddler(tiddler);
tiddler = Tiddler("Tea")
tiddler.fields = {u'geo.lat': u'', u'geo.long': u''}
bag.add_tiddler(tiddler);
tiddler = Tiddler("BT Centre")
tiddler.fields = {u'geo.lat': u'51.5156', u'geo.long': u'-0.0978'}
bag.add_tiddler(tiddler);
tiddler = Tiddler("Private Eye")
tiddler.fields = {u'geo.lat': u'51.514657', u'geo.long': u'-0.133652'}
bag.add_tiddler(tiddler);
tiddler = Tiddler("Centre Point Tower")
tiddler.fields = {u'geo.lat': u'51.515861', u'geo.long': u'-0.129694'}
bag.add_tiddler(tiddler);
tiddler = Tiddler("Ofcom")
tiddler.fields = {u'geo.lat': u'51.5079', u'geo.long': u'-0.0953'}
bag.add_tiddler(tiddler);
tiddler = Tiddler("Duxford")
tiddler.fields = {u'geo.lat': u'52.09306', u'geo.long': u'0.12944'}
bag.add_tiddler(tiddler);
tiddler = Tiddler("Sinclair Research")
tiddler.fields = {u'geo.lat': u'52.20225', u'geo.long': u'0.13357'}
bag.add_tiddler(tiddler);
tiddler = Tiddler("BBC Micro")
tiddler.fields = {u'geo.lat': u'', u'geo.long': u''}
bag.add_tiddler(tiddler);
tiddler = Tiddler("Invader")
tiddler.fields = {u'geo.lat': u'', u'geo.long': u''}
bag.add_tiddler(tiddler);
tiddler = Tiddler("@dopplr")
tiddler.fields = {u'geo.lat': u'51.525490', u'geo.long': u'-0.088250'}
bag.add_tiddler(tiddler);
tiddler = Tiddler("@schoolofeverything")
tiddler.fields = {u'geo.lat': u'51.52869', u'geo.long': u'-0.05369'}
bag.add_tiddler(tiddler);
tiddler = Tiddler("@thoughtworks")
tiddler.fields = {u'geo.lat': u'', u'geo.long': u''}
bag.add_tiddler(tiddler);
tiddler = Tiddler("The Source")
tiddler.fields = {u'geo.lat': u'51.51589', u'geo.long': u'-0.12523'}
bag.add_tiddler(tiddler);
tiddler = Tiddler("Stock Exchange")
tiddler.fields = {u'geo.lat': u'51.515', u'geo.long': u'-0.099028'}
bag.add_tiddler(tiddler);
tiddler = Tiddler("The Barbican")
tiddler.fields = {u'geo.lat': u'51.51917', u'geo.long': u'-0.09389'}
bag.add_tiddler(tiddler);
tiddler = Tiddler("Griffins")
tiddler.fields = {u'geo.lat': u'51.5086', u'geo.long': u'-0.1206'}
bag.add_tiddler(tiddler);
tiddler = Tiddler("The Gherkin")
tiddler.fields = {u'geo.lat': u'51.51444', u'geo.long': u'-0.08028'}
bag.add_tiddler(tiddler);
tiddler = Tiddler("Rosetta Stone")
tiddler.fields = {u'geo.lat': u'51.519444', u'geo.long': u'-0.126944'}
bag.add_tiddler(tiddler);
tiddler = Tiddler("British Museum")
tiddler.fields = {u'geo.lat': u'51.51944', u'geo.long': u'-0.12694'}
bag.add_tiddler(tiddler);
tiddler = Tiddler("St Paul's Cathedral")
tiddler.fields = {u'geo.lat': u'51.5138', u'geo.long': u'-0.098'}
bag.add_tiddler(tiddler);
tiddler = Tiddler("Baynard's Castle")
tiddler.fields = {u'geo.lat': u'51.51139', u'geo.long': u'-0.09861'}
bag.add_tiddler(tiddler);
tiddler = Tiddler("Fleet Street")
tiddler.fields = {u'geo.lat': u'51.51417', u'geo.long': u'-0.10889'}
bag.add_tiddler(tiddler);
tiddler = Tiddler("St Bride's")
tiddler.fields = {u'geo.lat': u'51.51389', u'geo.long': u'-0.10583'}
bag.add_tiddler(tiddler);
tiddler = Tiddler("NESTA")
tiddler.fields = {u'geo.lat': u'51.516525', u'geo.long': u'-0.108623'}
bag.add_tiddler(tiddler);
tiddler = Tiddler("John Snow")
tiddler.fields = {u'geo.lat': u'', u'geo.long': u''}
bag.add_tiddler(tiddler);
tiddler = Tiddler("Soho")
#.........这里部分代码省略.........
示例12: Tiddler
# 需要导入模块: from tiddlyweb.model.bag import Bag [as 别名]
# 或者: from tiddlyweb.model.bag.Bag import add_tiddler [as 别名]
TiddlerOne.text = u'c tiddler one content'
TiddlerOne.tags = ['tagone', 'tagtwo']
TiddlerTwo = Tiddler('TiddlerTwo')
TiddlerTwo.modifier = u'AuthorTwo'
TiddlerTwo.text = u'b tiddler two content'
TiddlerThree = Tiddler('TiddlerThree')
TiddlerThree.modifier = u'AuthorThree'
TiddlerThree.text = u'a tiddler three content'
TiddlerThree.tags = [u'tagone', u'tagthree']
tiddlers = [TiddlerOne, TiddlerTwo, TiddlerThree]
bagone = Bag(name='bagone')
bagone.add_tiddler(tiddlers[0])
bagtwo = Bag(name='bagtwo')
bagtwo.add_tiddler(tiddlers[1])
bagthree = Bag(name='bagthree')
bagthree.add_tiddler(tiddlers[2])
bagfour = Bag(name='bagfour')
bagfour.add_tiddler(tiddlers[0])
bagfour.add_tiddler(tiddlers[1])
bagfour.add_tiddler(tiddlers[2])
recipe_list = [
[bagone, u'select=title:TiddlerOne'],
[bagtwo, u'select=title:TiddlerTwo'],
[bagthree, u'select=tag:tagone;select=tag:tagthree']
]
示例13: Bag
# 需要导入模块: from tiddlyweb.model.bag import Bag [as 别名]
# 或者: from tiddlyweb.model.bag.Bag import add_tiddler [as 别名]
# to the database to load the policies of
# the same bag over and over.
policies = {}
for tiddler in tiddlers:
bag_name = tiddler.bag
try:
policies[bag_name].allows(usersign, 'read')
except KeyError:
bag = Bag(tiddler.bag)
bag = store.get(bag)
policy = bag.policy
policies[bag_name] = policy
policies[bag_name].allows(usersign, 'read')
tiddler.recipe = recipe.name
tmp_bag.add_tiddler(tiddler)
return send_tiddlers(environ, start_response, tmp_bag)
def list(environ, start_response):
"""
Get a list of all recipes the current user can read.
"""
store = environ['tiddlyweb.store']
recipes = store.list_recipes()
kept_recipes = []
for recipe in recipes:
try:
recipe = store.get(recipe)
recipe.policy.allows(environ['tiddlyweb.usersign'], 'read')
示例14: HTTP404
# 需要导入模块: from tiddlyweb.model.bag import Bag [as 别名]
# 或者: from tiddlyweb.model.bag.Bag import add_tiddler [as 别名]
except NoRecipeError, exc:
raise HTTP404('unable to edit %s, recipe %s not found: %s' % (tiddler.title, recipe_name, exc))
except NoBagError, exc:
raise HTTP404('unable to edit %s: %s' % (tiddler.title, exc))
bag = Bag(tiddler.bag)
try:
tiddler = store.get(tiddler)
bag = store.get(bag)
except (NoTiddlerError, NoBagError), exc:
raise HTTP404('tiddler %s not found: %s' % (tiddler.title, exc))
bag.policy.allows(usersign, 'write')
output_bag = Bag('output', tmpbag=True)
output_bag.add_tiddler(tiddler)
def create_dynamic_recipe(environ,recipeDefinition):
recipe = Recipe('myRecipe')
recipe.set_recipe(recipeDefinition)
recipe.store = environ['tiddlyweb.store']
return recipe
def add_magic_tiddler(bag, title, text):
tiddler = Tiddler(title, 'tmp')
tiddler.text = text
tiddler.tags = ['excludeLists']
bag.add_tiddler(tiddler)
add_magic_tiddler(output_bag, 'MainMenu', '[[Back to TiddlyWeb|%s]]' % tiddler_url(environ, tiddler))
add_magic_tiddler(output_bag, 'DefaultTiddlers', '[[%s]]' % tiddler_name)
add_magic_tiddler(output_bag, 'SiteTitle', 'Editor for %s' % tiddler_name)
示例15: tiddler_as
# 需要导入模块: from tiddlyweb.model.bag import Bag [as 别名]
# 或者: from tiddlyweb.model.bag.Bag import add_tiddler [as 别名]
def tiddler_as(self, tiddler):
bag = Bag('tmpbag', tmpbag=True)
bag.add_tiddler(tiddler)
return self.list_tiddlers(bag)