def _gethumans(dbName, templateName):
'''Return string for humans.txt.'''
db = _dbAndClient(dbName)[0]
metaDocs = _getMeta(db)
# Get templateName from db.templates.
humans = db['templates'].find_one({'name': templateName})
if not humans:
raise ValueError(
'%s not found in templates collection.'%(templateName))
ldr = jinja2.DictLoader({'humans': humans['data']})
env = jinja2.Environment(loader=ldr)
tmplt = env.get_template('humans')
# Mogrify template variables into values in the rendered page.
try:
humanStr = tmplt.render(metaDocs)
except Exception as e:
# The template probably tried to get something that isn't in meta.
# Or something.
e.args += (', '.join([
'Num Docs found in meta: %d'%(len(metaDocs)),
'Names found in meta: %s'%(metaDocs.keys()),
'Template Doc: %s'%(templateName),
]),)
raise
return humanStr
评论列表
文章目录