本文整理汇总了Python中stalker.db.session.DBSession.flush方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.flush方法的具体用法?Python DBSession.flush怎么用?Python DBSession.flush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stalker.db.session.DBSession
的用法示例。
在下文中一共展示了DBSession.flush方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_entity_statuses
# 需要导入模块: from stalker.db.session import DBSession [as 别名]
# 或者: from stalker.db.session.DBSession import flush [as 别名]
def create_entity_statuses(entity_type="", status_names=None, status_codes=None, user=None):
"""creates the default task statuses
"""
if not entity_type:
raise ValueError("Please supply entity_type")
if not status_names:
raise ValueError("Please supply status names")
if not status_codes:
raise ValueError("Please supply status codes")
# create statuses for entity
from stalker import Status, StatusList
logger.debug("Creating %s Statuses" % entity_type)
statuses = Status.query.filter(Status.name.in_(status_names)).all()
status_names_in_db = map(lambda x: x.name, statuses)
for name, code in zip(status_names, status_codes):
if name not in status_names_in_db:
logger.debug("Creating Status: %s (%s)" % (name, code))
new_status = Status(name=name, code=code, created_by=user, updated_by=user)
statuses.append(new_status)
DBSession.add(new_status)
# create the Status List
status_list = StatusList.query.filter(StatusList.target_entity_type == entity_type).first()
if status_list is None:
logger.debug("No %s Status List found, creating new!" % entity_type)
status_list = StatusList(
name="%s Statuses" % entity_type, target_entity_type=entity_type, created_by=user, updated_by=user
)
else:
logger.debug("%s Status List already created, updating statuses" % entity_type)
status_list.statuses = statuses
DBSession.add(status_list)
try:
DBSession.commit()
except IntegrityError as e:
logger.debug("error in DBSession.commit, rolling back: %s" % e)
DBSession.rollback()
else:
logger.debug("Created %s Statuses successfully" % entity_type)
DBSession.flush()