当前位置: 首页>>代码示例>>Python>>正文


Python DBSession.execute方法代码示例

本文整理汇总了Python中sys2do.model.DBSession.execute方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.execute方法的具体用法?Python DBSession.execute怎么用?Python DBSession.execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sys2do.model.DBSession的用法示例。


在下文中一共展示了DBSession.execute方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: save_update

# 需要导入模块: from sys2do.model import DBSession [as 别名]
# 或者: from sys2do.model.DBSession import execute [as 别名]
    def save_update(self):
        id = _g('id')
#        try:
        obj = DBSession.query(InventoryLocation).get(id)
        for f in ["name", "manager", "address", "remark", ]: setattr(obj, f, _g(f))

        #if the parent_id change:
        old_parent_id = unicode(obj.parent_id) if obj.parent_id else None
        new_parent_id = _g('parent_id') or None

        if old_parent_id != new_parent_id:

            old_full_path = obj.full_path
            old_full_ids = "%s|" % obj.full_path_ids
            if new_parent_id:
                new_parent = DBSession.query(InventoryLocation).get(new_parent_id)
                new_full_path = new_parent.full_path + obj.name
                new_full_ids = "%s|%s|" % (new_parent.full_path_ids, obj.id)
            else:
                new_full_path = obj.name
                new_full_ids = "%s|" % obj.id
            sql1 = "update master_inventory_location set full_path = replace(full_path,'%s','%s') where full_path like '%s%%';"
            sql2 = "update master_inventory_location set full_path_ids = replace(full_path_ids,'%s','%s') where full_path_ids like '%s%%';"
            DBSession.execute(sql1 % (old_full_path, new_full_path, old_full_path))
            DBSession.execute(sql2 % (old_full_ids, new_full_ids, old_full_ids))

            obj.parent_id = new_parent_id
            obj.full_path = new_full_path
            obj.full_path_ids = new_full_ids[:-1]

        DBSession.commit()
        flash(MSG_SAVE_SUCC, MESSAGE_INFO)
#        except:
#            DBSession.rollback()
#            _error(traceback.print_exc())
#            flash(MSG_SERVER_ERROR, MESSAGE_ERROR)
        return redirect(self.default())
开发者ID:LamCiuLoeng,项目名称:Logistics,代码行数:39,代码来源:warehouse.py


注:本文中的sys2do.model.DBSession.execute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。