本文整理汇总了Python中dao.Dao.delete_pending_tournament方法的典型用法代码示例。如果您正苦于以下问题:Python Dao.delete_pending_tournament方法的具体用法?Python Dao.delete_pending_tournament怎么用?Python Dao.delete_pending_tournament使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dao.Dao
的用法示例。
在下文中一共展示了Dao.delete_pending_tournament方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import delete_pending_tournament [as 别名]
def post(self, region, id):
dao = Dao(region, mongo_client=mongo_client)
pending_tournament = dao.get_pending_tournament_by_id(ObjectId(id))
if not pending_tournament:
return 'No pending tournament found with that id.', 400
user = get_user_from_request(request, dao)
if not user:
return 'Permission denied', 403
if not is_user_admin_for_region(user, pending_tournament.regions):
return 'Permission denied', 403
new_player_names = []
for mapping in pending_tournament.alias_to_id_map:
if mapping["player_id"] == None:
new_player_names.append(mapping["player_alias"])
for player_name in new_player_names:
player = Player.create_with_default_values(player_name, region)
player_id = dao.insert_player(player)
pending_tournament.set_alias_id_mapping(player_name, player_id)
dao.update_pending_tournament(pending_tournament)
try:
tournament = Tournament.from_pending_tournament(pending_tournament)
tournament_id = dao.insert_tournament(tournament)
dao.delete_pending_tournament(pending_tournament)
return {"success": True, "tournament_id": str(tournament_id)}
except ValueError:
return 'Not all player aliases in this pending tournament have been mapped to player ids.', 400
示例2: delete
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import delete_pending_tournament [as 别名]
def delete(self, region, id):
""" Deletes a pending tournament.
If a (non-pending) tournament with this id exists, tell the user they can't do that.
Route restricted to admins for this region. """
dao = Dao(region, mongo_client=mongo_client)
user = get_user_from_request(request, dao)
if not user:
return 'Permission denied', 403
pending_tournament = dao.get_pending_tournament_by_id(ObjectId(id))
if not pending_tournament:
tournament = dao.get_tournament_by_id(ObjectId(id))
if not tournament:
return "No pending tournament found with that id.", 400
else:
if not is_user_admin_for_regions(user, tournament.regions):
return 'Permission denied', 403
else:
return "Cannot delete a finalized tournament.", 400
if not is_user_admin_for_regions(user, pending_tournament.regions):
return 'Permission denied', 403
dao.delete_pending_tournament(pending_tournament)
return {"success": True}
示例3: post
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import delete_pending_tournament [as 别名]
def post(self, region, id):
print "finalize tournament post"
dao = Dao(region, mongo_client=mongo_client)
if not dao:
return 'Dao not found', 404
pending_tournament = None
try:
pending_tournament = dao.get_pending_tournament_by_id(ObjectId(id))
except:
return 'Invalid ObjectID', 400
if not pending_tournament:
return 'No pending tournament found with that id.', 400
user = get_user_from_request(request, dao)
if not user:
return 'Permission denied', 403
if not is_user_admin_for_regions(user, pending_tournament.regions):
return 'Permission denied', 403
# Make sure multiple player aliases don't map to a single player ID.
player_ids = set()
for mapping in pending_tournament.alias_to_id_map:
if mapping.player_id is not None:
if mapping.player_id in player_ids:
return "Player id %s is already mapped" % mapping.player_id, 400
else:
player_ids.add(mapping.player_id)
new_player_names = []
for mapping in pending_tournament.alias_to_id_map:
if mapping.player_id is None:
new_player_names.append(mapping.player_alias)
for player_name in new_player_names:
player = M.Player.create_with_default_values(player_name, region)
player_id = dao.insert_player(player)
pending_tournament.set_alias_id_mapping(player_name, player_id)
# validate players in this tournament
for mapping in pending_tournament.alias_to_id_map:
try:
player_id = mapping.player_id
# TODO: reduce queries to DB by batching
player = dao.get_player_by_id(player_id)
if player.merged:
return "Player {} has already been merged".format(player.name), 400
except:
return "Not all player ids are valid", 400
try:
dao.update_pending_tournament(pending_tournament)
tournament = M.Tournament.from_pending_tournament(
pending_tournament)
tournament_id = dao.insert_tournament(tournament)
dao.delete_pending_tournament(pending_tournament)
return {"success": True, "tournament_id": str(tournament_id)}
except ValueError as e:
print e
return 'Not all player aliases in this pending tournament have been mapped to player ids.', 400
except:
return 'Dao threw an error somewhere', 400
示例4: delete
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import delete_pending_tournament [as 别名]
def delete(self, region, id):
""" Deletes a tournament.
Route restricted to admins for this region.
Be VERY careful when using this """
dao = Dao(region, mongo_client=mongo_client)
if not dao:
return 'Dao not found', 404
user = get_user_from_request(request, dao)
if not user:
return 'Permission denied', 403
tournament_to_delete = None
try:
tournament_to_delete = dao.get_pending_tournament_by_id(
ObjectId(id))
except:
return 'Invalid ObjectID', 400
if tournament_to_delete: # its a pending tournament
if not is_user_admin_for_regions(user, tournament_to_delete.regions):
return 'Permission denied', 403
dao.delete_pending_tournament(tournament_to_delete)
else: # not a pending tournament, might be a finalized tournament
tournament_to_delete = dao.get_tournament_by_id(
ObjectId(id)) # ID must be valid if we got here
if not tournament_to_delete: # can't find anything, whoops
return "No tournament (pending or finalized) found with that id.", 404
if not is_user_admin_for_regions(user, tournament_to_delete.regions):
return 'Permission denied', 403
dao.delete_tournament(tournament_to_delete)
return {"success": True}
示例5: TestDAO
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import delete_pending_tournament [as 别名]
#.........这里部分代码省略.........
self.assertEquals(pending_tournament.id, self.pending_tournament_id_1)
self.assertEquals(pending_tournament.type,
self.pending_tournament_type_1)
self.assertEquals(pending_tournament.date,
self.pending_tournament_date_1)
self.assertEquals(pending_tournament.name,
self.pending_tournament_name_1)
self.assertEquals(pending_tournament.matches,
self.pending_tournament_matches_1)
self.assertEquals(pending_tournament.players,
self.pending_tournament_players_1)
self.assertEquals(pending_tournament.regions,
self.pending_tournament_regions_1)
def test_get_pending_tournament_by_id(self):
pending_tournament = self.norcal_dao.get_pending_tournament_by_id(
self.pending_tournament_id_1)
self.assertEquals(pending_tournament.id, self.pending_tournament_id_1)
self.assertEquals(pending_tournament.type,
self.pending_tournament_type_1)
self.assertEquals(pending_tournament.date,
self.pending_tournament_date_1)
self.assertEquals(pending_tournament.name,
self.pending_tournament_name_1)
self.assertEquals(pending_tournament.matches,
self.pending_tournament_matches_1)
self.assertEquals(pending_tournament.players,
self.pending_tournament_players_1)
self.assertEquals(pending_tournament.regions,
self.pending_tournament_regions_1)
self.assertIsNone(self.norcal_dao.get_tournament_by_id(ObjectId()))
def test_delete_pending_tournament(self):
pending_tournament = self.norcal_dao.get_pending_tournament_by_id(
self.pending_tournament_id_1)
self.norcal_dao.delete_pending_tournament(pending_tournament)
deleted_tournament = self.norcal_dao.get_pending_tournament_by_id(
self.pending_tournament_id_1)
self.assertIsNone(deleted_tournament)
def test_update_tournament(self):
tournament_1 = self.norcal_dao.get_tournament_by_id(
self.tournament_id_1)
self.assertEquals(tournament_1.id, self.tournament_id_1)
self.assertEquals(tournament_1.type, self.tournament_type_1)
self.assertEquals(tournament_1.date, self.tournament_date_1)
self.assertEquals(tournament_1.name, self.tournament_name_1)
self.assertEquals(tournament_1.matches, self.tournament_matches_1)
self.assertEquals(tournament_1.players, self.tournament_players_1)
self.assertEquals(tournament_1.regions, self.tournament_regions_1)
tournament_2 = self.norcal_dao.get_tournament_by_id(
self.tournament_id_2)
self.assertEquals(tournament_2.id, self.tournament_id_2)
self.assertEquals(tournament_2.type, self.tournament_type_2)
self.assertEquals(tournament_2.date, self.tournament_date_2)
self.assertEquals(tournament_2.name, self.tournament_name_2)
self.assertEquals(tournament_2.matches, self.tournament_matches_2)
self.assertEquals(tournament_2.players, self.tournament_players_2)
self.assertEquals(tournament_2.regions, self.tournament_regions_2)
tournament_2_name_new = 'new tournament 2 name'
tournament_2.name = tournament_2_name_new
示例6: TestDAO
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import delete_pending_tournament [as 别名]
#.........这里部分代码省略.........
self.assertEquals(pending_tournament.name, self.pending_tournament_name_1)
self.assertEquals(pending_tournament.matches, self.pending_tournament_matches_1)
self.assertEquals(pending_tournament.players, self.pending_tournament_players_1)
self.assertEquals(pending_tournament.regions, self.pending_tournament_regions_1)
def test_get_all_pending_tournaments_for_region(self):
pending_tournaments = self.norcal_dao.get_all_pending_tournaments(regions=['norcal'])
self.assertEquals(len(pending_tournaments), 1)
pending_tournament = pending_tournaments[0]
self.assertEquals(pending_tournament.id, self.pending_tournament_id_1)
self.assertEquals(pending_tournament.type, self.pending_tournament_type_1)
self.assertEquals(pending_tournament.raw, '')
self.assertEquals(pending_tournament.date, self.pending_tournament_date_1)
self.assertEquals(pending_tournament.name, self.pending_tournament_name_1)
self.assertEquals(pending_tournament.matches, self.pending_tournament_matches_1)
self.assertEquals(pending_tournament.players, self.pending_tournament_players_1)
self.assertEquals(pending_tournament.regions, self.pending_tournament_regions_1)
def test_get_pending_tournament_by_id(self):
pending_tournament = self.norcal_dao.get_pending_tournament_by_id(self.pending_tournament_id_1)
self.assertEquals(pending_tournament.id, self.pending_tournament_id_1)
self.assertEquals(pending_tournament.type, self.pending_tournament_type_1)
self.assertEquals(pending_tournament.raw, self.pending_tournament_raw_1)
self.assertEquals(pending_tournament.date, self.pending_tournament_date_1)
self.assertEquals(pending_tournament.name, self.pending_tournament_name_1)
self.assertEquals(pending_tournament.matches, self.pending_tournament_matches_1)
self.assertEquals(pending_tournament.players, self.pending_tournament_players_1)
self.assertEquals(pending_tournament.regions, self.pending_tournament_regions_1)
self.assertIsNone(self.norcal_dao.get_tournament_by_id(ObjectId()))
def test_delete_pending_tournament(self):
pending_tournament = self.norcal_dao.get_pending_tournament_by_id(self.pending_tournament_id_1)
self.norcal_dao.delete_pending_tournament(pending_tournament)
deleted_tournament = self.norcal_dao.get_pending_tournament_by_id(self.pending_tournament_id_1)
self.assertIsNone(deleted_tournament)
def test_update_tournament(self):
tournament_1 = self.norcal_dao.get_tournament_by_id(self.tournament_id_1)
self.assertEquals(tournament_1.id, self.tournament_id_1)
self.assertEquals(tournament_1.type, self.tournament_type_1)
self.assertEquals(tournament_1.raw, self.tournament_raw_1)
self.assertEquals(tournament_1.date, self.tournament_date_1)
self.assertEquals(tournament_1.name, self.tournament_name_1)
self.assertEquals(tournament_1.matches, self.tournament_matches_1)
self.assertEquals(tournament_1.players, self.tournament_players_1)
self.assertEquals(tournament_1.regions, self.tournament_regions_1)
tournament_2 = self.norcal_dao.get_tournament_by_id(self.tournament_id_2)
self.assertEquals(tournament_2.id, self.tournament_id_2)
self.assertEquals(tournament_2.type, self.tournament_type_2)
self.assertEquals(tournament_2.raw, self.tournament_raw_2)
self.assertEquals(tournament_2.date, self.tournament_date_2)
self.assertEquals(tournament_2.name, self.tournament_name_2)
self.assertEquals(tournament_2.matches, self.tournament_matches_2)
self.assertEquals(tournament_2.players, self.tournament_players_2)
self.assertEquals(tournament_2.regions, self.tournament_regions_2)
tournament_2_raw_new = 'asdfasdf'
tournament_2_name_new = 'new tournament 2 name'
tournament_2.raw = tournament_2_raw_new
tournament_2.name = tournament_2_name_new