本文整理汇总了Python中tornado.template.Loader.generate方法的典型用法代码示例。如果您正苦于以下问题:Python Loader.generate方法的具体用法?Python Loader.generate怎么用?Python Loader.generate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tornado.template.Loader
的用法示例。
在下文中一共展示了Loader.generate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: gen_db_model
# 需要导入模块: from tornado.template import Loader [as 别名]
# 或者: from tornado.template.Loader import generate [as 别名]
def gen_db_model(self, schema_name, table_name):
sql = """ SELECT column_name, column_default, data_type, column_key, is_nullable,
character_maximum_length, column_comment
FROM information_schema.columns
WHERE TABLE_SCHEMA = :schema_name AND
TABLE_NAME = :table_name
ORDER BY ORDINAL_POSITION"""
with self.create_session(self._default_db) as session:
entities = session.execute(sql, dict(schema_name=schema_name, table_name=table_name))
metas = [GenMeta(entity) for entity in entities if entity[0] != 'pkid']
model_meta = DbModelMeta()
model_meta.table_metas = metas
for meta in metas:
if model_meta.has_id is False:
model_meta.has_id = meta.column_name == 'id'
model_meta.is_string_id = meta.column_name == 'id' and \
u'varchar' == meta.data_type
if model_meta.has_created_at is False:
model_meta.has_created_at = meta.column_name == 'created_at'
if model_meta.has_updated_at is False:
model_meta.has_updated_at = meta.column_name == 'updated_at'
if model_meta.has_is_deleted is False:
model_meta.has_is_deleted = meta.column_name == 'is_deleted'
model_meta.class_name = inflection.singularize(inflection.camelize(table_name))
template_path = os.path.join(os.path.dirname(__file__))
t = Loader(template_path, **{}).load('model.tpl')
print t.generate(**model_meta.__dict__)