本文整理汇总了Python中tiddlyweb.model.tiddler.Tiddler.fields[key]方法的典型用法代码示例。如果您正苦于以下问题:Python Tiddler.fields[key]方法的具体用法?Python Tiddler.fields[key]怎么用?Python Tiddler.fields[key]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tiddlyweb.model.tiddler.Tiddler
的用法示例。
在下文中一共展示了Tiddler.fields[key]方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _manage_update_routes
# 需要导入模块: from tiddlyweb.model.tiddler import Tiddler [as 别名]
# 或者: from tiddlyweb.model.tiddler.Tiddler import fields[key] [as 别名]
def _manage_update_routes(environ, gym):
"""
Update routes with new information.
"""
store = environ['tiddlyweb.store']
query = environ['tiddlyweb.query']
existing_titles = query.get('title', [])
count = len(existing_titles)
index = 0
delete = query.get('delete', [])
lead_route = query.get(LEAD_FIELD, [])
while index < count:
title = existing_titles[index]
tiddler = Tiddler(title, '%s_climbs' % gym)
try:
tiddler = store.get(tiddler)
if title in delete:
original_bag = tiddler.bag
tiddler.bag = '%s_archive' % gym
store.put(tiddler)
tiddler.bag = original_bag
store.delete(tiddler)
index += 1
continue
except StoreError:
pass
changed = False
for key in ROUTE_FIELDS:
value = query.get(key, [''])[index]
if tiddler.fields[key] != value:
tiddler.fields[key] = value
changed = True
if LEAD_FIELD in tiddler.fields and title not in lead_route:
del tiddler.fields[LEAD_FIELD]
changed = True
elif title in lead_route and LEAD_FIELD not in tiddler.fields:
tiddler.fields[LEAD_FIELD] = '1'
changed = True
if changed:
store.put(tiddler)
index += 1
try:
title = query.get('title', [])[index]
except IndexError:
title = str(uuid4())
tiddler = Tiddler(title, '%s_climbs' % gym)
new_route = False
if 'new_one' in lead_route:
tiddler.fields[LEAD_FIELD] = '1'
for key in ROUTE_FIELDS:
value = query.get(key, [''])[index]
if value == '':
continue
new_route = True
tiddler.fields[key] = value
if new_route:
store.put(tiddler)
raise HTTP303(server_base_url(environ) + '/manager/%s' % gym)
示例2: csvimport
# 需要导入模块: from tiddlyweb.model.tiddler import Tiddler [as 别名]
# 或者: from tiddlyweb.model.tiddler.Tiddler import fields[key] [as 别名]
def csvimport(args):
"""Import a csv file as tiddlers. <bagname>"""
store = get_store(config)
try:
bag_name = args[0]
store.get(Bag(bag_name))
except IndexError:
usage('you must include a bag name')
except StoreError:
usage('bag %s does not exist' % bag_name)
tiddler_reader = DictReader(sys.stdin)
for tiddler_data in tiddler_reader:
try:
title = tiddler_data['title']
del tiddler_data['title']
except KeyError:
title = str(uuid4())
tiddler = Tiddler(title, bag_name)
for key, value in tiddler_data.iteritems():
if key is None:
continue
if key == 'tags':
value = string_to_tags_list(value)
if key in CORE_TIDDLER_ATTRS:
setattr(tiddler, key, value)
else:
tiddler.fields[key] = value
if binary_tiddler(tiddler):
try:
tiddler.text = b64decode(tiddler.text)
except TypeError, exc:
raise TiddlerFormatError(
'unable to decode b64 tiddler: %s: %s'
% (tiddler.title, exc))
store.put(tiddler)