Exemplo n.º 1
0
def output( ):
	id = getSingleField( 'id', request )
	player_name = getSingleField( 'player', request )
	ladder_id = getSingleField( 'ladder', request )
	limit = getSingleField( 'limit', request, 18 )
	ret = ''
	try:
		s = db.sessionmaker()
		if player_name and ladder_id:
			ladder = db.GetLadder( ladder_id )
			player = db.GetPlayer( player_name )
			template = env.get_template('viewmatchlist.html')
			header_string = 'Matches for %s on ladder %s'%(player.nick,ladder.name)
			matches = s.query( Match ).filter(Match.ladder_id == ladder_id).order_by(Match.date.desc()).all()
			ret = template.render(matches=matches, header=header_string )
		elif ladder_id:
			ladder = db.GetLadder( ladder_id )
			header_string = 'Matches on ladder %s'%(ladder.name)
			template = env.get_template('viewmatchlist.html')
			matches = s.query( Match ).filter(Match.ladder_id == ladder_id).order_by(Match.date.desc()).all()
			ret = template.render(matches=matches, header=header_string )
		elif player_name:
			player = db.GetPlayer( player_name )
			template = env.get_template('viewmatchlist.html')
			header_string = 'Matches for %s'%(player.nick)
			results = s.query( Result ).filter( Result.player_id == player.id).order_by(Result.date.desc())
			matches = []
			for r in results:
				matches.append( r.match )
			ret = template.render(matches=matches, header=header_string )
		elif not id:
			template = env.get_template('viewmatchgrid.html')
			matches = s.query( Match ).order_by(Match.date.desc())[:limit]
			ret = template.render( matches=matches, limit=limit )
		else:
			match = s.query( Match ).options(eagerload('settings')).filter(Match.id == id ).first()
			template = env.get_template('viewmatch.html')
			opt_headers = ['key','val','wl/bl']
			ret = template.render(ladder=match.ladder, matchinfo=MatchInfoToTableAdapter(match) )
		s.close()
		return ret
		
	except ElementNotFoundException, e:
		err_msg="ladder with id %s not found"%(str(id))
Exemplo n.º 2
0
def output( ):
	try:
		id = getSingleField( 'id', request )
		lad = db.GetLadder( id )
		rank_table = GlobalRankingAlgoSelector.GetWebRepresentation( db.GetRanks( id ), db )
		template = env.get_template('scoreboard.html')
		return template.render( rank_table=rank_table, ladder=lad )

	except ElementNotFoundException, e:
		err_msg="ladder with id %s not found"%(str(id))
Exemplo n.º 3
0
def output( ):
	id = getSingleField( 'id', request )

	try:
		ladder = db.GetLadder( id )
		template = env.get_template('viewrules.html')
		opts = db.GetOptions( id )
		options = LadderOptionsAdapter( opts , ladder )
		return template.render(ladder=ladder, laddertable=LadderInfoToTableAdapter(ladder), options=options )

	except ElementNotFoundException, e:
		template = env.get_template('error.html')
		return template.render( err_msg="ladder with id %s not found"%(str(id)) )
Exemplo n.º 4
0
def output( ):
	limit = int(getSingleField( 'limit', request, 18 ))
	s = db.session()
	template = env.get_template('viewmaplist.html')
	if limit > -1:
		maps = s.query( Map ).all()#order_by(Map.name.desc()).limit(limit).all()
	else:
		maps = s.query( Map ).order_by(Map.name.desc()).all()
	ret = template.render( maps=maps, limit=limit )
	try:

		s.close()
		return ret
		
	except ElementNotFoundException, e:
		err_msg="map with id %s not found"%(str(id))
Exemplo n.º 5
0
def output( ):
	player_name = getSingleField( 'player', request )
	order = getSingleField( 'order', request , 'nick')
	ladder_id = getSingleField( 'ladder', request )
	try:
		s = db.sessionmaker()
		if player_name:
			player = db.GetPlayer( player_name )
			ladders = db.GetLadderByPlayer( player.id )
			played = dict()
			positions = dict()
			for ladder in ladders:
				positions[ladder.id] = db.GetPlayerPosition( ladder.id, player.id )
				played[ladder.id] = s.query( Result.id ).filter( Result.ladder_id == ladder.id ).filter( Result.player_id == player.id ).count()

			results = s.query( Result ).filter( Result.player_id == player.id).order_by(Result.date.desc())[0:5]
			matches = []
			for r in results:
				matches.append( r.match )

			template = env.get_template('viewplayer.html')
			s.close()
			return template.render(player=player,ladders=ladders, positions=positions,played=played,matches=matches )
		else:
			asc = getSingleField( 'asc', request, 'False' )
			if not asc:
				asc = 'False'
			q = s.query( Player, func.count(Result.id).label('played')).outerjoin( (Result, Result.player_id == Player.id ) )\
				.filter( Player.id.in_(s.query( Result.player_id ).filter( Player.id == Result.player_id  ) ) ) \
				.filter( Result.player_id == Player.id ).group_by( Player.id )
			if ladder_id:
				q = q.filter( Player.id.in_( s.query( Result.player_id ).filter( Result.ladder_id == ladder_id ) ) )
			if order == 'nick':
				q = q.order_by( SortAsc( Player.nick, asc ) )
			elif order == 'id' :
				q = q.order_by( SortAsc( Player.id, asc ) )
			else:
				order = 'played'
				q = q.order_by( SortAsc( func.count(Result.id), asc ) )

			limit = int(getSingleField( 'limit', request, q.count() ))
			offset = int(getSingleField( 'offset', request, 0 ))
			players = q[offset:offset+limit-1]
			template = env.get_template('viewplayerlist.html')
			s.close()
			return template.render(players=players,offset=offset,limit=limit,order=order,asc=asc )

	except ElementNotFoundException, e:
		err_msg="player %s not found"%(str(player_name))
Exemplo n.º 6
0
def output( ):
	id = getSingleField( 'id', request, '-1' )
	try:
		s = db.session()
		if id == '-1':
			print 'LPLP %s'%id
			ladder_list = []
			ladder_triple_list = s.query(Ladder).order_by( Ladder.name )
			if ladder_triple_list.count() < 1:
				raise ElementNotFoundException('djwp')
			#ladder_triple_list = [db.GetLadder( 17 )]
			for  l in ladder_triple_list:
				ladder_id = l.id
				ladder_name = l.name
				ladder_description = l.description
				player_count = s.query( Result.id ).group_by( Result.player_id ).\
					filter(Result.ladder_id == ladder_id).count()
				match_query = s.query( Match.id,Match.date ).\
					filter(Match.ladder_id == ladder_id)
				match_count = match_query.count()
				last_match = match_query.order_by( Match.date.desc() ).first()

				item = dict()
				item['player_count'] = player_count
				item['match_count'] = match_count
				item['last_match'] = last_match
				item['name'] = ladder_name
				item['description'] = ladder_description
				item['id'] = ladder_id
				try:
					ranks = db.GetRanks( ladder_id, None, 3 )
					item['ranks'] = GlobalRankingAlgoSelector.GetWebRepresentation( ranks, db )
				except Exception, e:
					item['ranks'] = None
				ladder_list.append( item )
			template = env.get_template('viewladderlist.html')
			s.close()
			return template.render(ladders=ladder_list )
		else: