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


Python Session.rollback方法代码示例

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


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

示例1: post

# 需要导入模块: from models import Session [as 别名]
# 或者: from models.Session import rollback [as 别名]
    def post(self):
        username = self.get_argument('username')
        game_id = self.get_argument('game_id')
        dispute_id = self.get_argument('dispute_id')
        shot_upheld = self.get_argument('dispute_upheld')
        gm_decision_reason = self.get_argument('gm_decision_reason')

        session = Session()
        try:
            dispute = session.query(Dispute).filter_by(id=dispute_id).one()
            shot = session.query(Shot).filter_by(id=dispute.shot_id).one()
            resolving_user = get_user(username=username)
            game = get_game(game_id)
            mission = get_mission(game_id=game_id, assassin_id=shot.assassin_id, target_id=shot.target_id, completed_timestamp=None)
            if resolving_user in game.game_masters:
                if shot_upheld == 'True':
                    game.mission_completed(mission)
                    dispute.shot_upheld = True
                else:
                    dispute.shot_upheld = False
                    target_usergame = get_usergame(shot.target_id, game.id)
                    if target_usergame.alive == None:
                        target_usergame.alive = True
                        session.add(target_usergame)
                dispute.gm_decision_reason = gm_decision_reason
                session.add(dispute)
                session.flush()
                session.commit()
                response_dict = get_response_dict(True)
                
            else:
                response_dict = get_response_dict(False, 'Only the game master can resolve a dispute')
        except Exception, e:
            session.rollback()
            response_dict = get_response_dict(False, e.message)
开发者ID:sosso,项目名称:Assassins-Server,代码行数:37,代码来源:game_action_handlers.py

示例2: post

# 需要导入模块: from models import Session [as 别名]
# 或者: from models.Session import rollback [as 别名]
    def post(self):
        username = self.get_argument('username')
        item_id = self.get_argument('item_id')
        try: file1 = self.request.files['file'][0]
        except: file1 = None
        final_string = ''
        session = Session()
        try:
            user = dbutils.get_or_create(session, User, username=username)
            item = dbutils.get_or_create(session, Item, item_id=item_id)
            item_completion = dbutils.get_or_create(session, ItemCompletion, item_id=item.id, user_id=user.id)

            if file1 is not None:
                original_fname = file1['filename']

                extension = os.path.splitext(original_fname)[1]
                final_filename = item_id + extension
                if not os.path.exists("./uploads"):
                    os.makedirs("./uploads")
                if not os.path.exists("./uploads/%s" % username):
                    os.makedirs("./uploads/%s" % username)
                output_file = open("./uploads/" + username + "/" + final_filename, 'wb')
                output_file.write(file1['body'])
                item_completion.file_path = "uploads/" + username + "/" + final_filename

            session.add(item_completion)
            session.commit()
            final_string = "You have crossed item " + item_id + " off your bucket list!"
        except Exception, e:
            session.rollback()
            logger.exception(e)
            final_string = "Oops!  Something went wrong.  Please try again"
开发者ID:sosso,项目名称:eashl_stats2,代码行数:34,代码来源:modelhandlers.py

示例3: BaseTest

# 需要导入模块: from models import Session [as 别名]
# 或者: from models.Session import rollback [as 别名]
class BaseTest(unittest.TestCase):
    
    def setUp(self):
        self.session = Session()
    
    def tearDown(self):
        self.session.rollback()
        Session.remove()
        clear_all()
开发者ID:sosso,项目名称:Assassins-Server,代码行数:11,代码来源:test_utils.py

示例4: load_fixtures

# 需要导入模块: from models import Session [as 别名]
# 或者: from models.Session import rollback [as 别名]
def load_fixtures():
    session = Session()
    try:
        for model, items in fixtures.items():
            for item in items:
                session.add(model(**item))
        session.commit()
    except:
        session.rollback()
开发者ID:junkafarian,项目名称:super-granny-geek,代码行数:11,代码来源:app.py

示例5: get

# 需要导入模块: from models import Session [as 别名]
# 或者: from models.Session import rollback [as 别名]
 def get(self):
     shot_id = self.get_argument('shot_id')
     session = Session()
     try:
         shot = get_shot(shot_id)
         response_dict = shot.get_api_response_dict()
     except Exception, e:
         session.rollback()
         response_dict = get_response_dict(False, e.message)
开发者ID:sosso,项目名称:Assassins-Server,代码行数:11,代码来源:game_action_handlers.py

示例6: post

# 需要导入模块: from models import Session [as 别名]
# 或者: from models.Session import rollback [as 别名]
    def post(self):
        game_id = self.get_argument('game_id')
        powerup_id = self.get_argument('powerup_id')

        session = Session()
        try:
            pass
        except Exception, e:
            session.rollback()
开发者ID:sosso,项目名称:Assassins-Server,代码行数:11,代码来源:game_master_handlers.py

示例7: main

# 需要导入模块: from models import Session [as 别名]
# 或者: from models.Session import rollback [as 别名]
def main():
    success = 0

    try:
        args = parse_arguments()
    except ArgumentError as e:
        return e

    try:
        fetch_environment_variables(args)
    except ArgumentError as e:
        return e

    session = Session()

    status = False

    if args.report_user and args.report_pass:
        auth = (args.report_user, args.report_pass)
    else:
        auth = ()

    try:
        if args.command == 'scanall':
            status = scanall(
                args.ss_url, session,
                report_url=args.report_url, report_auth=auth,
                throttle_time=args.throttle
            )
        elif args.command == 'scan':
            session_id = str(uuid4())
            status = scan(
                args.aip, args.ss_url, session,
                report_url=args.report_url, report_auth=auth,
                session_id=session_id
            )
        else:
            return Exception('Error: "{}" is not a valid command.'.format(args.command))

        session.commit()
    except Exception as e:
        session.rollback()
        if args.debug:
            traceback.print_exc()
        return e
    finally:
        session.close()

    if status is True:
        success = 0
    elif status is False:
        success = 1
    else:
        success = status

    return success
开发者ID:VonRosenchild,项目名称:fixity,代码行数:58,代码来源:fixity.py

示例8: get

# 需要导入模块: from models import Session [as 别名]
# 或者: from models.Session import rollback [as 别名]
    def get(self):
        username = self.get_argument('username')

        session = Session()
        try:
            user = dbutils.get_or_create(session, User, username=username)
            final_string = "User creation successful!"
        except Exception, e:
            session.rollback()
            final_string = "User creation failed."
开发者ID:sosso,项目名称:eashl_stats2,代码行数:12,代码来源:modelhandlers.py

示例9: post

# 需要导入模块: from models import Session [as 别名]
# 或者: from models.Session import rollback [as 别名]
    def post(self):
        username = self.get_argument('username')
        password = self.get_argument('password')

        session = Session()
        result_dict = {}
        try:
            picture_binary = self.request.files['profile_picture'][0]['body']    
            create_user(username = username, password=password, profile_picture=picture_binary)
            result_dict['result'] = "SUCCESS"
        except Exception, e:
            session.rollback()
            result_dict['result'] = "ERROR"
            result_dict['reason'] = e.message
开发者ID:sosso,项目名称:Assassins-Server,代码行数:16,代码来源:dispute_handlers.py

示例10: get

# 需要导入模块: from models import Session [as 别名]
# 或者: from models.Session import rollback [as 别名]
 def get(self):
     logger = logging.getLogger('ViewAvailablePowerups')
     try:
         game_id = self.get_argument('game_id')
         session = Session()
         powerup_json_array = []
         powerups_from_db = list_enabled_powerups(game_id)
         for powerup in powerups_from_db:
             powerup_json_array.append(powerup.get_api_response_dict())
         return_obj = powerup_json_array
     except Exception, e:
         logger.exception(e)
         session.rollback()
         return_obj = []
开发者ID:sosso,项目名称:Assassins-Server,代码行数:16,代码来源:powerup_handlers.py

示例11: post

# 需要导入模块: from models import Session [as 别名]
# 或者: from models.Session import rollback [as 别名]
 def post(self):
     logger = logging.getLogger("BuyPowerup")
     session = Session()
     try:
         username = self.get_argument('username')
         item_id = self.get_argument('item_id')
         game_id = self.get_argument('game_id')
     
         user = get_user(username)
         purchase_powerup(user.id, game_id, item_id)
         session.commit()
         result_dict = get_response_dict(True)
     except Exception, e:
         logger.exception(e)
         session.rollback()
         result_dict = get_response_dict(False, e.message)
开发者ID:sosso,项目名称:Assassins-Server,代码行数:18,代码来源:powerup_handlers.py

示例12: post

# 需要导入模块: from models import Session [as 别名]
# 或者: from models.Session import rollback [as 别名]
 def post(self):
     logger = logging.getLogger('CreateUserHandler')
     username = self.get_argument('username')
     password = self.get_argument('password')
     email = self.get_argument('email')
     logger.info('Create user request received, args grabbed')
     session = Session()
     result_dict = {}
     try:
         picture_binary = self.request.files['profile_picture'][0]['body']    
         create_user(username=username, password=password, profile_picture_binary=picture_binary, email=email)
         result_dict = get_response_dict(True)
         result_dict['username'] = username
     except Exception, e:
         logger.exception(e)
         session.rollback()
         result_dict = get_response_dict(False, e.message)
开发者ID:sosso,项目名称:Assassins-Server,代码行数:19,代码来源:account_handlers.py

示例13: analy

# 需要导入模块: from models import Session [as 别名]
# 或者: from models.Session import rollback [as 别名]
def analy():
    
    token=request.form.get("token",None)
    number=request.form.get("number",None)    
    r=request.form.get("r",None)
    
    result=[]
    for t1 in range(1,15):
        obj=[]
        for t2 in range(1,15):
            obj.append(0)
        result.append(obj)
    
    #插入数据
    session=Session();
    try:
        obj=Message(token,number,r)
        session.add(obj)
        session.flush()
        session.commit()
    except Exception:
        session.rollback()
        session.query(Message).filter_by(token=token,number=number).update({"message":r,"updateTime":time.strftime("%Y-%m-%d %H:%M:%S")})
        session.flush()    
    
    #删除无效数据
    t=datetime.datetime.now()-datetime.timedelta(seconds=20)
    session.query(Message).filter(Message.updateTime < t).delete()
    session.commit()
    
    objs=session.query(Message).filter(number==number)
    nums=0
    for obj in objs:
        temp=json.loads(obj.message)
        for index1,t1 in enumerate(temp):
            for index2,t2 in enumerate(t1):
                if t2 == 1:
                    result[index1][index2]+=1
        nums+=1                
    response=make_response(json.dumps({"result":result,'nums':nums}))
    response.headers['Content-Type']="application/json"
    return response
开发者ID:wangjun,项目名称:idleSchedule,代码行数:44,代码来源:app.py


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