本文整理汇总了Python中mediacore.model.meta.DBSession.connection方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.connection方法的具体用法?Python DBSession.connection怎么用?Python DBSession.connection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mediacore.model.meta.DBSession
的用法示例。
在下文中一共展示了DBSession.connection方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: fetch_and_create_tags
# 需要导入模块: from mediacore.model.meta import DBSession [as 别名]
# 或者: from mediacore.model.meta.DBSession import connection [as 别名]
def fetch_and_create_tags(tag_names):
# copy the tag_names list
new_tag_names = tag_names[:]
# find tag names that already exist (case insensitive match)
# and remove those names from our list
lower_case_tags = [t.lower() for t in new_tag_names]
existing_tags = DBSession.query(Tag).\
filter(
func.lower(Tag.name).in_(lower_case_tags)
).all()
for t in existing_tags:
for n in new_tag_names[:]:
if n.lower() == t.name.lower():
new_tag_names.remove(n)
break
# create the tags that don't yet exist
if new_tag_names:
new_tags = [{'name': n, 'slug': slugify(n)} for n in new_tag_names]
DBSession.connection().execute(tags.insert(), new_tags)
DBSession.flush()
existing_tags += DBSession.query(Tag)\
.filter(
Tag.slug.in_([t['slug'] for t in new_tags])
).all()
return existing_tags