本文整理汇总了Python中persistence.PersistenceManager.get_tourney_by_id方法的典型用法代码示例。如果您正苦于以下问题:Python PersistenceManager.get_tourney_by_id方法的具体用法?Python PersistenceManager.get_tourney_by_id怎么用?Python PersistenceManager.get_tourney_by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类persistence.PersistenceManager
的用法示例。
在下文中一共展示了PersistenceManager.get_tourney_by_id方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: put_or_post
# 需要导入模块: from persistence import PersistenceManager [as 别名]
# 或者: from persistence.PersistenceManager import get_tourney_by_id [as 别名]
def put_or_post(self, helper, tourney_id):
if not helper.isint(tourney_id):
return helper.bail("invalid tourney_id %d passed to player get" % (tourney_id), 403)
pm = PersistenceManager(myapp.db_connector)
tourney = pm.get_tourney_by_id(tourney_id)
if tourney is None:
return helper.bail("failed to look up tourney id %d for player get" % (tourney_id), 403)
json_data = None
try:
json_data = request.get_json(force=True)
except Exception:
return helper.bail("bad json received!", 403)
if json_data is not None:
bail = helper.check_token(json_data, tourney)
if bail:
return bail, None
if not json_data.has_key(PLAYERS):
return helper.bail("player put missing player key", 403), None
bail, tl1, tl2 = helper.extract_players(json_data, tourney)
if bail:
return bail
pm.db_connector.get_session().commit()
players = []
for player in tourney.tourney_players:
xws = None
tourney_list = player.get_first_tourney_list()
if tourney_list and tourney_list.archtype_list:
xws = XWSListConverter(tourney_list.archtype_list).data
players.append({NAME: player.get_player_name(), ID: player.id, XWS: xws})
return None, players
示例2: unlock_tourney
# 需要导入模块: from persistence import PersistenceManager [as 别名]
# 或者: from persistence.PersistenceManager import get_tourney_by_id [as 别名]
def unlock_tourney():
key = request.args.get('key')
tourney_id = request.args.get('tourney_id')
pm = PersistenceManager(myapp.db_connector)
state = ""
try:
tourney = pm.get_tourney_by_id(tourney_id)
if len(key) and tourney.email == key:
response = jsonify( result="success")
if tourney.locked == True: #flip the lock
tourney.locked = False
state = "unlocked"
else:
tourney.locked = True
state = "locked"
event = Event(remote_address=myapp.remote_address(request),
event_date=func.now(),
event="lock/unlock tourney",
event_details="set tourney %s to state %s" % ( tourney.tourney_name, state ))
pm.db_connector.get_session().add(event)
pm.db_connector.get_session().commit()
return response
else:
response = jsonify(result="fail")
return response
except Exception, e:
error = "someone tried to unlock tourney_id " + tourney_id + " with email address " + key + " ( expected " + tourney.email + " ) "
mail_error( error )
response = jsonify(message=str(e))
response.status_code = (500)
return response
示例3: get_tourney_data
# 需要导入模块: from persistence import PersistenceManager [as 别名]
# 或者: from persistence.PersistenceManager import get_tourney_by_id [as 别名]
def get_tourney_data():
tourney_id = request.args['tourney_id']
pm = PersistenceManager(myapp.db_connector)
tourney = pm.get_tourney_by_id(tourney_id)
de = RankingEditor( pm, tourney )
return de.get_json()
示例4: get_tourney_details
# 需要导入模块: from persistence import PersistenceManager [as 别名]
# 或者: from persistence.PersistenceManager import get_tourney_by_id [as 别名]
def get_tourney_details():
tourney_id = request.args.get('tourney_id')
pm = PersistenceManager(myapp.db_connector)
tourney = pm.get_tourney_by_id(tourney_id)
unlocked = True
if tourney.locked:
unlocked = False
return render_template('edit_tourney.html', tourney_id=tourney_id,
tourney=tourney,
unlocked=unlocked )
示例5: update_tourney_details
# 需要导入模块: from persistence import PersistenceManager [as 别名]
# 或者: from persistence.PersistenceManager import get_tourney_by_id [as 别名]
def update_tourney_details():
tourney_id = request.form['tourney_id']
name = decode( request.form['name'] )
type = request.form['tourney_type']
print request.form['datepicker']
mmddyyyy = request.form['datepicker'].split('/')
date = datetime.date( int(mmddyyyy[2]),int(mmddyyyy[0]), int(mmddyyyy[1])) #YYYY, MM, DD
round_length = request.form['round_length_userdef']
tourney_format_def = request.form['tourney_format_dropdown']
tourney_format_custom = request.form['tourney_format_custom']
participant_count = int(request.form['participant_count'])
country = decode(request.form['country'])
state = decode(request.form['state'])
city = decode(request.form['city'])
venue = decode(request.form['venue'])
tourney_format = None
if tourney_format_def is None or len(tourney_format_def) == 0:
if tourney_format_custom is None or len(tourney_format_custom) == 0:
tourney_format = xwingmetadata.format_default
else:
tourney_format = decode(tourney_format_custom)
else:
tourney_format = str(tourney_format_def)
pm = PersistenceManager(myapp.db_connector)
tourney = pm.get_tourney_by_id(tourney_id)
tourney.tourney_name = name
tourney.tourney_type = type
tourney.tourney_date = date
tourney.round_length = round_length
tourney.format = tourney_format
tourney.participant_count = participant_count
tourney.venue.country = country
tourney.venue.state = state
tourney.venue.city = city
tourney.venue.venue = venue
event = Event(remote_address=myapp.remote_address(request),
event_date=func.now(),
event="edit tourney information",
event_details="edited " + name )
pm.db_connector.get_session().add(event)
pm.db_connector.get_session().commit()
return redirect( url_for( 'get_tourney_details', tourney_id=tourney_id) )
示例6: export_tourney_lists
# 需要导入模块: from persistence import PersistenceManager [as 别名]
# 或者: from persistence.PersistenceManager import get_tourney_by_id [as 别名]
def export_tourney_lists():
tourney_id = request.args.get('tourney_id')
pm = PersistenceManager(myapp.db_connector)
tourney = pm.get_tourney_by_id(tourney_id)
ret = get_tourney_lists_as_text(tourney)
event = Event(remote_address=myapp.remote_address(request),
event_date=func.now(),
event="export tourney lists",
event_details="exported tourney %s" % ( tourney.tourney_name ))
pm.db_connector.get_session().add(event)
pm.db_connector.get_session().commit()
return csv_response( ret, "tourney_list_download.csv")
示例7: edit_tourney_details
# 需要导入模块: from persistence import PersistenceManager [as 别名]
# 或者: from persistence.PersistenceManager import get_tourney_by_id [as 别名]
def edit_tourney_details():
tourney_id = request.args.get('tourney_id')
pm = PersistenceManager(myapp.db_connector)
tourney = pm.get_tourney_by_id(tourney_id)
tourney_date = tourney.tourney_date
date_str = "%d/%d/%d" % ( tourney_date.month, tourney_date.day, tourney_date.year)
print "tourney date is " + date_str
return render_template('edit_tourney_details.html', tourney_id=tourney_id,
tourney=tourney,
tourney_formats = xwingmetadata.formats,
tourney_date = date_str,
unlocked=False )
示例8: get
# 需要导入模块: from persistence import PersistenceManager [as 别名]
# 或者: from persistence.PersistenceManager import get_tourney_by_id [as 别名]
def get(self, tourney_id):
helper = TournamentApiHelper()
if not helper.isint(tourney_id):
return helper.bail("invalid tourney_id %d passed to player get" % ( tourney_id), 403)
pm = PersistenceManager(myapp.db_connector)
tourney = pm.get_tourney_by_id(tourney_id)
if tourney is None:
return helper.bail("failed to look up tourney id %d for player get" % ( tourney_id), 403)
players = []
for player in tourney.tourney_players:
players.append({NAME: player.get_player_name(), ID: player.id})
response = jsonify({PLAYERS: players})
response.status_code = 200
return response
示例9: post
# 需要导入模块: from persistence import PersistenceManager [as 别名]
# 或者: from persistence.PersistenceManager import get_tourney_by_id [as 别名]
def post(self, tourney_id, player_id):
pm = PersistenceManager(myapp.db_connector)
helper = TournamentApiHelper(pm)
json_data = None
try:
json_data = request.get_json(force=True)
except Exception:
return helper.bail("bad json received!", 403)
if not helper.isint(tourney_id):
return helper.bail("invalid tourney_id %d passed to player post" % (tourney_id), 400)
if not helper.isint(player_id):
return helper.bail("invalid player %d passed to player post" % (player_id), 400)
pm = PersistenceManager(myapp.db_connector)
tourney = pm.get_tourney_by_id(tourney_id)
bail = helper.check_token(json_data, tourney)
if bail:
return bail
player = tourney.get_player_by_id(player_id)
if player is None:
return helper.bail("couldn't find player %d, bailing out" % (player_id), 400)
dirty = False
# add list via XWS
if XWS in json_data:
dirty = True
try:
tourney_list = player.tourney_lists[-1]
XWSToJuggler(json_data[XWS]).convert(pm, tourney_list)
except:
pm.db_connector.get_session().rollback()
return helper.bail('Could not add list via XWS', 400)
# other potential edits
if dirty:
pm.db_connector.get_session().commit()
return jsonify({
'player': {
'id': player.id,
'tourney_id': tourney.id,
'name': player.get_player_name(),
}
})
示例10: get
# 需要导入模块: from persistence import PersistenceManager [as 别名]
# 或者: from persistence.PersistenceManager import get_tourney_by_id [as 别名]
def get(self, tourney_id):
pm = PersistenceManager(myapp.db_connector)
t = pm.get_tourney_by_id(tourney_id)
if t is None:
response = jsonify(message="tourney %d not found" % (tourney_id))
response.status_code = 404
return response
# and log it
event = Event(remote_address=myapp.remote_address(request),
event_date=func.now(),
event="API",
event_details="tournament API: tourney GET")
pm.db_connector.get_session().add(event)
pm.db_connector.get_session().commit()
json = TourneyToJsonConverter().convert(t,provide_points=True)
return jsonify(json)
示例11: edit_ranking_row
# 需要导入模块: from persistence import PersistenceManager [as 别名]
# 或者: from persistence.PersistenceManager import get_tourney_by_id [as 别名]
def edit_ranking_row():
#see https://editor.datatables.net/manual/server
tourney_id = request.args['tourney_id']
pm = PersistenceManager(myapp.db_connector)
tourney = pm.get_tourney_by_id(tourney_id)
de = RankingEditor(pm, tourney)
event = Event(remote_address=myapp.remote_address(request),
event_date=func.now(),
event="edit ranking row")
player_name = request.values['data[player_name]']
player_name = decode(player_name)
ret = de.set_and_get_json(request, player_name, event)
event.event_details = event.event_details + " in tourney " + tourney.tourney_name
pm.db_connector.get_session().add(event)
pm.db_connector.get_session().commit()
return ret
示例12: post
# 需要导入模块: from persistence import PersistenceManager [as 别名]
# 或者: from persistence.PersistenceManager import get_tourney_by_id [as 别名]
def post(self, tourney_id):
helper = TournamentApiHelper()
try:
email = request.form['email']
except KeyError:
json_data = request.get_json(force=True)
email = json_data['email']
pm = PersistenceManager(myapp.db_connector)
tourney = pm.get_tourney_by_id(tourney_id)
if tourney is None:
return helper.bail("tourney %d not found" % ( tourney_id ), 404)
if email != tourney.email:
return helper.bail("incorrect email for tourney {}".format(tourney_id), 404)
if tourney.api_token is None:
tourney.api_token = str(uuid.uuid4())
pm.db_connector.get_session().commit()
return jsonify({"api_token": tourney.api_token})
示例13: delete
# 需要导入模块: from persistence import PersistenceManager [as 别名]
# 或者: from persistence.PersistenceManager import get_tourney_by_id [as 别名]
def delete(self, tourney_id, player_id):
helper = TournamentApiHelper()
json_data = None
try:
json_data = request.get_json(force=True)
except Exception:
return helper.bail("bad json received!", 403)
if not helper.isint(tourney_id):
return helper.bail("invalid tourney_id %d passed to player delete" % ( tourney_id), 403)
if not helper.isint(player_id):
return helper.bail("invalid player %d passed to player delete" % ( player_id), 403)
pm = PersistenceManager(myapp.db_connector)
tourney = pm.get_tourney_by_id(tourney_id)
bail = helper.check_token(json_data, tourney)
if bail:
return bail
player = tourney.get_player_by_id(player_id)
if player is None:
return helper.bail("couldn't find player %d, bailing out" % ( player_id), 403)
pm.db_connector.get_session().delete(player)
pm.db_connector.get_session().commit()
示例14: enter_list
# 需要导入模块: from persistence import PersistenceManager [as 别名]
# 或者: from persistence.PersistenceManager import get_tourney_by_id [as 别名]
def enter_list():
tourney_id = request.args.get('tourney')
tourney_list_id = request.args.get('tourney_list_id')
pm = PersistenceManager(myapp.db_connector)
tourney_list = None
tourney = None
if tourney_list_id is None:
tourney = pm.get_tourney_by_id(tourney_id)
tourney_list = pm.get_random_tourney_list(tourney)
if tourney_list is None:
return redirect(url_for( "success", tourney_name=tourney.tourney_name ) )
else:
tourney_list = pm.get_tourney_list(tourney_list_id)
tourney = tourney_list.tourney
m = xwingmetadata.XWingMetaData()
image_src = None
if tourney_list.image is not None:
image_src = urllib.quote(tourney_list.image)
event = Event(remote_address=myapp.remote_address(request),
event_date=func.now(),
event="create list",
event_details="created list %d for tourney %s" % ( tourney_list.id, tourney.tourney_name ))
pm = PersistenceManager(myapp.db_connector)
pm.db_connector.get_session().add(event)
pm.db_connector.get_session().commit()
return render_template('list_entry.html',
meta=m,
image_src=image_src,
tourney_list=tourney_list,
tourney_list_id=tourney_list.id,
tourney_id=tourney.id,
tourney=tourney)
示例15: delete
# 需要导入模块: from persistence import PersistenceManager [as 别名]
# 或者: from persistence.PersistenceManager import get_tourney_by_id [as 别名]
def delete(self, tourney_id):
pm = PersistenceManager(myapp.db_connector)
helper = TournamentApiHelper(pm)
self.helper = helper
t = pm.get_tourney_by_id(tourney_id)
if t is None:
return helper.bail("tourney %d not found" % (tourney_id), 403)
json_data = None
try:
json_data = request.get_json(force=True)
except Exception:
return helper.bail("bad json received!", 403)
if json_data is None:
return helper.bail("delete call for tourney_id %d missing json payload, giving up " % (tourney_id), 403)
bail = helper.check_token(json_data, t)
if bail:
return bail
# whew. aaaaalmost there...
try:
pm.delete_tourney_by_id(tourney_id)
except Exception:
return helper.bail("unable to delete tourney %d, bailing out " % (tourney_id), 403)
# and log it
event = Event(remote_address=myapp.remote_address(request),
event_date=func.now(),
event="API",
event_details="tournament API: tourney delete %d" % (tourney_id))
pm.db_connector.get_session().add(event)
pm.db_connector.get_session().commit()
response = jsonify(message="deleted tourney id %d" % (tourney_id))
response.status_code = 204
return response