本文整理汇总了Python中dao.Dao.get_pending_tournament_by_id方法的典型用法代码示例。如果您正苦于以下问题:Python Dao.get_pending_tournament_by_id方法的具体用法?Python Dao.get_pending_tournament_by_id怎么用?Python Dao.get_pending_tournament_by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dao.Dao
的用法示例。
在下文中一共展示了Dao.get_pending_tournament_by_id方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import get_pending_tournament_by_id [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
示例2: post
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import get_pending_tournament_by_id [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
示例3: delete
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import get_pending_tournament_by_id [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}
示例4: delete
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import get_pending_tournament_by_id [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: get
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import get_pending_tournament_by_id [as 别名]
def get(self, region, id):
dao = Dao(region, mongo_client=mongo_client)
if not dao:
return 'Dao not found', 404
response = None
tournament = None
try:
tournament = dao.get_tournament_by_id(ObjectId(id))
except:
return 'Invalid ObjectID', 400
if tournament is not None:
response = convert_tournament_to_response(tournament, dao)
else:
user = get_user_from_request(request, dao)
# this usage is safe, if the ID was fake, we would have already
# blown the coop above
pending_tournament = dao.get_pending_tournament_by_id(ObjectId(id))
if not pending_tournament:
return 'Not found!', 404
if not user:
return 'Permission denied', 403
if not is_user_admin_for_regions(user, pending_tournament.regions):
return 'Permission denied', 403
response = pending_tournament.dump(context='web')
return response
示例6: get
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import get_pending_tournament_by_id [as 别名]
def get(self, region, id):
dao = Dao(region, mongo_client=mongo_client)
response = None
tournament = dao.get_tournament_by_id(ObjectId(id))
if tournament is not None:
response = convert_tournament_to_response(tournament, dao)
else:
pending_tournament = dao.get_pending_tournament_by_id(ObjectId(id))
response = convert_pending_tournament_to_response(pending_tournament, dao)
return response
示例7: put
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import get_pending_tournament_by_id [as 别名]
def put(self, region, id):
print "in pending tournament put"
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.", 404
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
args = pending_tournament_put_parser.parse_args()
data = {'alias_to_id_map': [M.AliasMapping.load(
alias_item, context='web') for alias_item in args['alias_to_id_map']]}
if not data:
return 'Request couldnt be converted to pending tournament', 400
try:
print "Incoming", data["alias_to_id_map"]
print "DB", pending_tournament.alias_to_id_map
for alias_item in data["alias_to_id_map"]:
player_alias = alias_item.player_alias
player_id = alias_item.player_id
pending_tournament.set_alias_id_mapping(
player_alias, player_id)
except:
print 'Error processing alias_to_id map'
return 'Error processing alias_to_id map', 400
try:
dao.update_pending_tournament(pending_tournament)
return pending_tournament.dump(context='web')
except:
return 'Encountered an error inserting pending tournament', 400
示例8: put
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import get_pending_tournament_by_id [as 别名]
def put(self, region, id):
"""
Currently only updates the alias_to_id_map in the pending tournament
"""
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
args = pending_tournament_put_parser.parse_args()
data = convert_request_to_pending_tournament(args)
pending_tournament.alias_to_id_map = data["alias_to_id_map"]
dao.update_pending_tournament(pending_tournament)
response = convert_pending_tournament_to_response(pending_tournament, dao)
return response
示例9: TestDAO
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import get_pending_tournament_by_id [as 别名]
#.........这里部分代码省略.........
self.assertNotEquals(self.norcal_dao.get_player_by_id(self.player_1_id), self.player_1)
self.assertEquals(self.norcal_dao.get_player_by_id(self.player_2_id), self.player_2)
self.assertEquals(self.norcal_dao.get_player_by_id(self.player_3_id), self.player_3)
self.assertEquals(self.norcal_dao.get_player_by_id(self.player_1_id), player_1_clone)
def test_add_alias_to_player(self):
new_alias = 'gaRRR'
lowercase_alias = 'garrr'
old_expected_aliases = ['gar', 'garr']
new_expected_aliases = ['gar', 'garr', 'garrr']
self.assertEquals(self.norcal_dao.get_player_by_id(self.player_1_id).aliases, old_expected_aliases)
self.assertEquals(self.player_1.aliases, old_expected_aliases)
self.norcal_dao.add_alias_to_player(self.player_1, new_alias)
self.assertEquals(self.norcal_dao.get_player_by_id(self.player_1_id).aliases, new_expected_aliases)
self.assertEquals(self.player_1.aliases, new_expected_aliases)
def test_add_alias_to_player_duplicate(self):
with self.assertRaises(DuplicateAliasException):
self.norcal_dao.add_alias_to_player(self.player_1, 'garr')
def test_update_player_name(self):
self.assertEquals(self.norcal_dao.get_player_by_id(self.player_1_id).name, 'gaR')
self.assertEquals(self.player_1.name, 'gaR')
self.norcal_dao.update_player_name(self.player_1, 'gaRR')
self.assertEquals(self.norcal_dao.get_player_by_id(self.player_1_id).name, 'gaRR')
self.assertEquals(self.player_1.name, 'gaRR')
def test_update_player_name_non_alias(self):
with self.assertRaises(InvalidNameException):
self.norcal_dao.update_player_name(self.player_1, 'asdf')
def test_update_pending_tournament(self):
pending_tournament_1 = self.norcal_dao.get_pending_tournament_by_id(self.pending_tournament_id_1)
self.assertEquals(pending_tournament_1.id, self.pending_tournament_id_1)
self.assertEquals(pending_tournament_1.type, self.pending_tournament_type_1)
self.assertEquals(pending_tournament_1.raw, self.pending_tournament_raw_1)
self.assertEquals(pending_tournament_1.date, self.pending_tournament_date_1)
self.assertEquals(pending_tournament_1.name, self.pending_tournament_name_1)
self.assertEquals(pending_tournament_1.matches, self.pending_tournament_matches_1)
self.assertEquals(pending_tournament_1.players, self.pending_tournament_players_1)
self.assertEquals(pending_tournament_1.regions, self.pending_tournament_regions_1)
pending_tournament_1_raw_new = 'asdfasdf'
pending_tournament_1_name_new = 'new pending tournament name'
pending_tournament_1.raw = pending_tournament_1_raw_new
pending_tournament_1.name = pending_tournament_1_name_new
self.norcal_dao.update_pending_tournament(pending_tournament_1)
pending_tournament_1 = self.norcal_dao.get_pending_tournament_by_id(self.pending_tournament_id_1)
self.assertEquals(pending_tournament_1.id, self.pending_tournament_id_1)
self.assertEquals(pending_tournament_1.type, self.pending_tournament_type_1)
self.assertEquals(pending_tournament_1.raw, pending_tournament_1_raw_new)
self.assertEquals(pending_tournament_1.date, self.pending_tournament_date_1)
self.assertEquals(pending_tournament_1.name, pending_tournament_1_name_new)
self.assertEquals(pending_tournament_1.matches, self.pending_tournament_matches_1)
self.assertEquals(pending_tournament_1.players, self.pending_tournament_players_1)
self.assertEquals(pending_tournament_1.regions, self.pending_tournament_regions_1)
def test_update_pending_tournament_empty_raw(self):
pending_tournament = self.norcal_dao.get_pending_tournament_by_id(self.pending_tournament_id_1)
pending_tournament.raw = ''
with self.assertRaises(UpdateTournamentException):
示例10: TestDAO
# 需要导入模块: from dao import Dao [as 别名]
# 或者: from dao.Dao import get_pending_tournament_by_id [as 别名]
#.........这里部分代码省略.........
self.player_1_id), player_1_clone)
def test_add_alias_to_player(self):
new_alias = 'gaRRR'
old_expected_aliases = ['gar', 'garr']
new_expected_aliases = ['gar', 'garr', 'garrr']
self.assertEquals(self.norcal_dao.get_player_by_id(
self.player_1_id).aliases, old_expected_aliases)
self.assertEquals(self.player_1.aliases, old_expected_aliases)
self.norcal_dao.add_alias_to_player(self.player_1, new_alias)
self.assertEquals(self.norcal_dao.get_player_by_id(
self.player_1_id).aliases, new_expected_aliases)
self.assertEquals(self.player_1.aliases, new_expected_aliases)
def test_add_alias_to_player_duplicate(self):
with self.assertRaises(DuplicateAliasException):
self.norcal_dao.add_alias_to_player(self.player_1, 'garr')
def test_update_player_name(self):
self.assertEquals(self.norcal_dao.get_player_by_id(
self.player_1_id).name, 'gaR')
self.assertEquals(self.player_1.name, 'gaR')
self.norcal_dao.update_player_name(self.player_1, 'gaRR')
self.assertEquals(self.norcal_dao.get_player_by_id(
self.player_1_id).name, 'gaRR')
self.assertEquals(self.player_1.name, 'gaRR')
def test_update_player_name_non_alias(self):
with self.assertRaises(InvalidNameException):
self.norcal_dao.update_player_name(self.player_1, 'asdf')
def test_update_pending_tournament(self):
pending_tournament_1 = self.norcal_dao.get_pending_tournament_by_id(
self.pending_tournament_id_1)
self.assertEquals(pending_tournament_1.id,
self.pending_tournament_id_1)
self.assertEquals(pending_tournament_1.type,
self.pending_tournament_type_1)
self.assertEquals(pending_tournament_1.raw_id,
self.pending_tournament_raw_id_1)
self.assertEquals(pending_tournament_1.date,
self.pending_tournament_date_1)
self.assertEquals(pending_tournament_1.name,
self.pending_tournament_name_1)
self.assertEquals(pending_tournament_1.matches,
self.pending_tournament_matches_1)
self.assertEquals(pending_tournament_1.players,
self.pending_tournament_players_1)
self.assertEquals(pending_tournament_1.regions,
self.pending_tournament_regions_1)
pending_tournament_1_name_new = 'new pending tournament name'
pending_tournament_1.name = pending_tournament_1_name_new
self.norcal_dao.update_pending_tournament(pending_tournament_1)
pending_tournament_1 = self.norcal_dao.get_pending_tournament_by_id(
self.pending_tournament_id_1)
self.assertEquals(pending_tournament_1.id,
self.pending_tournament_id_1)
self.assertEquals(pending_tournament_1.type,
self.pending_tournament_type_1)
self.assertEquals(pending_tournament_1.date,
self.pending_tournament_date_1)