• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python dbsession.commit函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中models.dbsession.commit函数的典型用法代码示例。如果您正苦于以下问题:Python commit函数的具体用法?Python commit怎么用?Python commit使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: create_levels

def create_levels(levels):
    ''' Create GameLevel objects based on XML data '''
    logging.info("Found %s game level(s)" % levels.get('count'))
    for index, level_elem in enumerate(levels.getchildren()):
        # GameLevel 0 is created automatically by the bootstrap
        if get_child_text(level_elem, 'number') != '0':
            try:
                number = get_child_text(level_elem, 'number')
                if GameLevel.by_number(number) is None:
                    game_level = GameLevel()
                    game_level.number = number
                    game_level.buyout = get_child_text(level_elem, 'buyout')
                    dbsession.add(game_level)
                else:
                    logging.info("GameLevel %d already exists, skipping" % number)
            except:
                logging.exception("Failed to import game level #%d" % (index + 1))
    dbsession.flush()
    game_levels = GameLevel.all()
    for index, game_level in enumerate(game_levels):
        if index + 1 < len(game_levels):
            game_level.next_level_id = game_levels[index + 1].id
            logging.info("%r -> %r" % (game_level, game_levels[index + 1]))
            dbsession.add(game_level)
    dbsession.commit()
开发者ID:AdaFormacion,项目名称:RootTheBox,代码行数:25,代码来源:xmlsetup.py


示例2: setUp

 def setUp(self):
     self.box, self.corp = create_box()
     self.static_flag = Flag.create_flag(
         _type=FLAG_STATIC,
         box=self.box,
         name="Static Flag",
         raw_token="statictoken",
         description="A static test token",
         value=100,
     )
     self.regex_flag = Flag.create_flag(
         _type=FLAG_REGEX,
         box=self.box,
         name="Regex Flag",
         raw_token="(f|F)oobar",
         description="A regex test token",
         value=200,
     )
     self.file_flag = Flag.create_flag(
         _type=FLAG_FILE,
         box=self.box,
         name="File Flag",
         raw_token="fdata",
         description="A file test token",
         value=300,
     )
     dbsession.add(self.static_flag)
     dbsession.add(self.regex_flag)
     dbsession.add(self.file_flag)
     dbsession.commit()
开发者ID:AdaFormacion,项目名称:RootTheBox,代码行数:30,代码来源:testModels.py


示例3: score_bots

def score_bots():
    ''' Award money for botnets '''
    logging.info("Scoring botnets, please wait ...")
    bot_manager = BotManager.instance()
    for team in Team.all():
        bots = bot_manager.by_team(team.name)
        reward = 0
        for bot in bots:
            try:
                reward += options.bot_reward
                bot.write_message({
                    'opcode': 'status',
                    'message': 'Collected $%d reward' % options.bot_reward
                })
            except:
                logging.info(
                    "Bot at %s failed to respond to score ping" % bot.remote_ip
                )
        if 0 < len(bots):
            logging.info("%s was awarded $%d for controlling %s bot(s)" % (
                team.name, reward, len(bots),
            ))
            bot_manager.add_rewards(team.name, options.bot_reward)
            bot_manager.notify_monitors(team.name)
            team.money += reward
            dbsession.add(team)
            dbsession.flush()
    dbsession.commit()
开发者ID:AnarKyx01,项目名称:RootTheBox,代码行数:28,代码来源:Scoreboard.py


示例4: create_team

def create_team():
    team = Team()
    team.name = "TestTeam"
    team.motto = "TestMotto"
    dbsession.add(team)
    dbsession.commit()
    return team
开发者ID:AdaFormacion,项目名称:RootTheBox,代码行数:7,代码来源:Helpers.py


示例5: delivered

 def delivered(cls, user_id, uuid):
     notify = dbsession.query(cls).filter(
         and_(cls.event_uuid == uuid, cls.user_id == user_id)
     ).first()
     notify.viewed = True
     dbsession.add(notify)
     dbsession.commit()
开发者ID:bincker,项目名称:RootTheBox,代码行数:7,代码来源:Notification.py


示例6: create_broadcast

 def create_broadcast(cls, team, title, message, icon=None):
     if not options.global_notification and team:
         cls.create_team(team, title, message, icon)
     else:
         for user in User.all_users():
             notification = cls._create(user, title, message, icon)
             dbsession.add(notification)
         dbsession.commit()
开发者ID:moloch--,项目名称:RootTheBox,代码行数:8,代码来源:Notification.py


示例7: create_choice

 def create_choice(cls, flag=None, item=None):
     ''' Create a choice and save it to the database '''
     if not flag:
         flag = cls.flag
     if not item:
         item = cls.item
     choice = cls._create(flag, unicode(item)[:256])
     dbsession.add(choice)
     dbsession.commit()
开发者ID:moloch--,项目名称:RootTheBox,代码行数:9,代码来源:FlagChoice.py


示例8: avatar

 def avatar(self):
     if self._avatar is not None:
         return self._avatar
     else:
         avatar = get_new_avatar('box')
         if not avatar.startswith("default_"):
             self._avatar = avatar
             dbsession.add(self)
             dbsession.commit()
         return avatar
开发者ID:moloch--,项目名称:RootTheBox,代码行数:10,代码来源:Box.py


示例9: create_user

def create_user():
    user = User.by_handle("HacKer")
    if user is None:
        user = User()
        user.handle = "HacKer"
        user.password = "TestPassword"
        user.bank_password = "Test123"
        dbsession.add(user)
        dbsession.commit()
    return user
开发者ID:AdaFormacion,项目名称:RootTheBox,代码行数:10,代码来源:Helpers.py


示例10: create_box

def create_box(corp=None):
    if corp is None:
        corp = create_corp()
    game_level = GameLevel.all()[0]
    box = Box(corporation_id=corp.id, game_level_id=game_level.id)
    box.name = "TestBox"
    box.description = "Some description"
    box.difficuly = "Easy"
    corp.boxes.append(box)
    dbsession.add(box)
    dbsession.commit()
    return box, corp
开发者ID:AdaFormacion,项目名称:RootTheBox,代码行数:12,代码来源:Helpers.py


示例11: create_categories

def create_categories(categories):
    ''' Create Category objects based on XML data '''
    logging.info("Found %s categories" % categories.get('count'))
    for index, cat_elem in enumerate(categories.getchildren()):
        try:
            category = Category()
            category.category = get_child_text(cat_elem, 'category')
            dbsession.add(category)
        except:
            logging.exception("Failed to import category #%d" % (index + 1))
    dbsession.flush()
    dbsession.commit()
开发者ID:moloch--,项目名称:RootTheBox,代码行数:12,代码来源:xmlsetup.py


示例12: __anonymous__

 def __anonymous__(cls, title, message, category, event_uuid, icon=None):
     ''' Creates anonysmous notification where user_id = NULL '''
     notification = Notification(
         user_id=None,
         event_uuid=event_uuid,
         title=unicode(title),
         message=unicode(message),
         category=category,
     )
     if icon is not None:
         notification.icon = icon
     dbsession.add(notification)
     dbsession.commit()
开发者ID:AdaFormacion,项目名称:RootTheBox,代码行数:13,代码来源:Notifier.py


示例13: avatar

 def avatar(self):
     if self._avatar is not None:
         return self._avatar
     else:
         if options.teams:
             avatar = get_new_avatar('team')
         else:
             avatar = get_new_avatar('user', True)
         if not avatar.startswith("default_"):
             self._avatar = avatar
             dbsession.add(self)
             dbsession.commit()
         return avatar
开发者ID:moloch--,项目名称:RootTheBox,代码行数:13,代码来源:Team.py


示例14: add_wordlist

def add_wordlist():
    if options.name is None:
        logging.critical("You must provide a name with --name")
        os._exit(1)
    if options.path is None:
        logging.critical("You must provide a path with --path")
        os._exit(1)
    try:
        wordlist = Wordlist(name=options.name, path=options.path)
        dbsession.add(wordlist)
        dbsession.commit()
    except ValidationError as error:
        logging.error("Failed to add wordlist: %s" % error)
开发者ID:fun-alex-alex2006hw,项目名称:Sonar-Server,代码行数:13,代码来源:__init__.py


示例15: __create__

 def __create__(cls, user, title, message, category, event_uuid, icon=None):
     ''' Create a notification and save it to the database '''
     notification = Notification(
         user_id=user.id,
         event_uuid=event_uuid,
         title=unicode(title),
         message=unicode(message),
         category=category,
     )
     if icon is not None:
         notification.icon = icon
     dbsession.add(notification)
     dbsession.commit()
开发者ID:AdaFormacion,项目名称:RootTheBox,代码行数:13,代码来源:Notifier.py


示例16: change_password

 def change_password(self):
     ''' Change a password '''
     user = self.get_current_user()
     old_password = self.get_argument('old_password', '')
     new_password = self.get_password()
     if user.validate_password(old_password):
         user.password = new_password
         dbsession.add(user)
         dbsession.commit()
         self.clear_all_cookies()
         self.redirect('/login')
     else:
         raise ValidationError("Old password is invalid")
开发者ID:fun-alex-alex2006hw,项目名称:Sonar-Server,代码行数:13,代码来源:UserHandlers.py


示例17: setUp

 def setUp(self):
     self.box, self.corp = create_box()
     self.static_flag = Flag.create_flag(
         _type=FLAG_STATIC,
         box=self.box,
         name="Static Flag",
         raw_token="statictoken",
         description="A static test token",
         value=100,
     )
     self.regex_flag = Flag.create_flag(
         _type=FLAG_REGEX,
         box=self.box,
         name="Regex Flag",
         raw_token="(f|F)oobar",
         description="A regex test token",
         value=200,
     )
     self.file_flag = Flag.create_flag(
         _type=FLAG_FILE,
         box=self.box,
         name="File Flag",
         raw_token="fdata",
         description="A file test token",
         value=300,
     )
     self.choice_flag = Flag.create_flag(
         _type=FLAG_CHOICE,
         box=self.box,
         name="Choice Flag",
         raw_token="fdata",
         description="A choice test token",
         value=400,
     )
     self.datetime_flag = Flag.create_flag(
         _type=FLAG_DATETIME,
         box=self.box,
         name="Datetime Flag",
         raw_token="2018-06-22 18:00:00",
         description="A datetime test token",
         value=500,
     )
     
     dbsession.add(self.static_flag)
     dbsession.add(self.regex_flag)
     dbsession.add(self.file_flag)
     dbsession.add(self.choice_flag)
     dbsession.add(self.datetime_flag)
     dbsession.commit()
开发者ID:moloch--,项目名称:RootTheBox,代码行数:49,代码来源:testModels.py


示例18: do_grant

 def do_grant(self, username):
     '''
     Add user permissions
     Usage: grant <handle>
     '''
     user = User.by_handle(username)
     if user is None:
         print(WARN + "'%s' user not found in database." % username)
     else:
         name = raw_input(PROMPT + "Add permission: ")
         permission = Permission(name=unicode(name), user_id=user.id)
         dbsession.add(permission)
         dbsession.add(user)
         dbsession.commit()
         print(INFO + "Successfully granted %s permissions to %s." % (name, user.handle,))
开发者ID:moloch--,项目名称:RootTheBox,代码行数:15,代码来源:recovery.py


示例19: do_mkteam

 def do_mkteam(self, nop):
     '''
     Make a new team.
     Usage: mkteam
     '''
     try:
         team = Team(
             name=unicode(raw_input(PROMPT + "Team name: ")),
             motto=unicode(raw_input(PROMPT + "Team motto: ")),
         )
         dbsession.add(team)
         dbsession.commit()
         print(INFO + "Successfully created new team.")
     except:
         print(WARN + "Failed to create new team.")
开发者ID:moloch--,项目名称:RootTheBox,代码行数:15,代码来源:recovery.py


示例20: push_user

 def push_user(self, team_id, user_id):
     ''' Push all unread notifications to open user websockets '''
     connections = self.get_user_connections(team_id, user_id)
     notifications = Notification.unread_by_user_id(user_id)
     logging.debug("User #%s has %d unread notification(s)" % (
         user_id, len(notifications)
     ))
     for notification in notifications:
         for connection in connections:
             self.safe_write_message(connection,
                                     notification.to_dict()
                                     )
         notification.viewed = True
         dbsession.add(notification)
     dbsession.commit()
开发者ID:AnarKyx01,项目名称:RootTheBox,代码行数:15,代码来源:EventManager.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python dbsession.flush函数代码示例发布时间:2022-05-27
下一篇:
Python dbsession.add函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap