本文整理汇总了Python中persistence.PersistenceManager类的典型用法代码示例。如果您正苦于以下问题:Python PersistenceManager类的具体用法?Python PersistenceManager怎么用?Python PersistenceManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PersistenceManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self,tsvfile):
if tsvfile is None:
return
pm = PersistenceManager( myapp.db_connector )
league_name = "X-Wing Vassal League Season Two"
league = pm.get_league(league_name)
self.tsv_players = {}
self.divisions = {}
with open(tsvfile, 'rU') as input:
reader = csv.reader( input,delimiter='\t' )
for row in reader:
person_name = unicode(row[0].strip())
email_address = row[1].strip()
challonge_name = unicode(row[2].strip())
time_zone = row[3].strip()
reddit_handle = row[4].strip()
challengeboards_name = row[5].strip()
tier_name = row[6].strip()
tier_number = row[7].strip()
division_name = row[8].strip()
division_letter = row[9].strip()
self.tsv_players[challonge_name] = { 'person_name': person_name,
'email_address' : email_address,
'challonge_name' : challonge_name,
'time_zone' : time_zone,
'reddit_handle' : reddit_handle,
'challengeboards_name':challengeboards_name ,
'tier_name' : tier_name,
'tier_number' : tier_number,
'division_name' : division_name,
'division_letter' : division_letter }
if not self.divisions.has_key( division_name ):
self.divisions[division_name] = { 'name': division_name, 'letter':division_letter, 'tier': tier_name}
示例2: get_tourney_data
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()
示例3: unlock_tourney
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
示例4: game
def game():
id = str(request.args.get('id'))
pm = PersistenceManager(myapp.db_connector)
game = pm.get_game(session,id)
if game == None:
return redirect(url_for('new'))
player1 = game.game_players[0]
player2 = game.game_players[1]
winning_player = "Unknown"
if game.game_winner is not None:
winning_player = game.game_winner.name
#summary_stats = GameSummaryStats(game)
game_tape = GameTape(game)
game_tape.score()
luck_result = pm.get_luck_score(session, game.id)
if luck_result is None:
luck_result = calculate_luck_result(game, game_tape=game_tape)
if luck_result is not None:
myapp.db_connector.get_session().add(luck_result)
myapp.db_connector.get_session().commit()
return render_template( 'game_summary.html',
game=game,
player1=player1,
player2=player2,
winner=winning_player,
game_tape=game_tape,
colorscale=colorscale() )
示例5: browse_list
def browse_list():
tourney_name = request.args.get('tourney')
admin = request.args.get('admin')
pm = PersistenceManager(myapp.db_connector)
tourney = pm.get_tourney(tourney_name)
tourney_lists = tourney.tourney_lists
return render_template( 'tourney_lists.html', tourney=tourney, tourney_lists=tourney_lists, admin=admin)
示例6: get
def get(self):
pm = PersistenceManager(myapp.db_connector)
leagues = pm.get_leagues()
ret = []
for l in leagues:
ret.append(l.id)
return jsonify({LEAGUES: ret})
示例7: add_squad
def add_squad():
data = request.json['data']
points = request.json['points']
faction = request.json['faction']
tourney_id = request.args.get('tourney_id')
tourney_list_id = request.args.get('tourney_list_id')
pm = PersistenceManager(myapp.db_connector)
tourney_list = pm.get_tourney_list(tourney_list_id)
tourney_list.faction = Faction.from_string( faction )
tourney_list.points = points
ships = []
for squad_member in data:
ship_pilot = pm.get_ship_pilot( squad_member['ship'], squad_member['pilot'] )
ship = Ship( ship_pilot_id=ship_pilot.id, tlist_id=tourney_list.id)
tourney_list.ships.append( ship )
for upgrade in squad_member['upgrades']:
upgrade = pm.get_upgrade(upgrade['type'], upgrade['name'])
ship_upgrade = ShipUpgrade( ship_id=ship.id,
upgrade=upgrade )
ship.upgrades.append( ship_upgrade )
ships.append( ship )
tourney_list.generate_hash_key()
pm.db_connector.get_session().add_all( ships )
pm.db_connector.get_session().commit()
return jsonify(tourney_id=tourney_id, tourney_list_id=tourney_list.id)
示例8: put_or_post
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
示例9: list_rank_generate_cache
def list_rank_generate_cache():
list_ranks = simple_cache.get('list-ranks')
if list_ranks is None:
pm = PersistenceManager(myapp.db_connector)
list_ranks = pm.get_list_ranks()
simple_cache.set( 'list-ranks', list_ranks, timeout=60*60)
return render_template("listrank_impl.html", ranks=list_ranks)
示例10: correct_list_points
def correct_list_points():
pm = PersistenceManager(myapp.db_connector)
lists = pm.get_all_lists()
for list in lists:
if list.points == 0 and len(list.ships) > 0:
print "list %d is a problem" % list.id
return redirect(url_for('tourneys') )
示例11: get_summaries
def get_summaries():
try:
summaries = simple_cache.get('banner-summary-data')
if summaries is None:
pm = PersistenceManager(myapp.db_connector)
summaries = pm.get_summaries()
simple_cache.set( 'banner-summary-data', summaries, timeout=5*60)
return json.dumps( summaries )
except Exception, e:
response = jsonify(message=str(e))
response.status_code = (500)
return response
示例12: delete_tourney
def delete_tourney():
tourney_name = request.args.get('tourney')
pm = PersistenceManager(myapp.db_connector)
pm.delete_tourney(tourney_name)
event = Event(remote_address=myapp.remote_address(request),
event_date=func.now(),
event="delete tourney",
event_details="deleted tourney %s" % ( tourney_name ))
pm.db_connector.get_session().add(event)
pm.db_connector.get_session().commit()
return redirect(url_for('tourneys') )
示例13: get_tourney_details
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 )
示例14: update_tourney_details
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) )
示例15: show_results
def show_results():
hashkey = request.args.get('hashkey')
pm = PersistenceManager(myapp.db_connector)
lists = pm.get_lists_for_hashkey(hashkey)
results = []
ret = {}
ret[ 'pretty_print'] = lists[0].pretty_print( manage_list=0, show_results=0)
ret['hashkey'] = lists[0].hashkey
for list in lists:
res = pm.get_round_results_for_list(list.id)
for r in res:
results.append(r)
ret[ "results"] = results
return render_template("show_results.html", data=ret)