本文整理汇总了Python中models.dbsession.commit函数的典型用法代码示例。如果您正苦于以下问题:Python commit函数的具体用法?Python commit怎么用?Python commit使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了commit函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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()
示例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()
示例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()
示例4: create_team
def create_team():
team = Team()
team.name = "TestTeam"
team.motto = "TestMotto"
dbsession.add(team)
dbsession.commit()
return team
示例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()
示例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()
示例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()
示例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
示例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
示例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
示例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()
示例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()
示例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
示例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)
示例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()