Matchplan/flaskapp/blueprints/tournament.py

36 lines
1.5 KiB
Python

from flask import Blueprint, render_template, request
from flaskapp.lib.toornament import get_toornament
import urllib.parse
bp = Blueprint('tournament', __name__)
@bp.route('/tournament/<int:tournament_id>')
def list_matches(tournament_id):
toornament = get_toornament()
tournament = toornament.get_tournament(tournament_id)
if request.args.get('participant_id'):
matches = toornament.get_matches(tournament_id, participant_id=request.args.get('participant_id'))
else:
matches = toornament.get_matches(tournament_id)
return render_template('match_list.html', matches=matches, tournament=tournament)
@bp.route('/tournament/<int:tournament_id>/match/<int:match_id>')
def show_match(tournament_id, match_id):
toornament = get_toornament()
tournament = toornament.get_tournament(tournament_id)
match = toornament.get_match(tournament_id, match_id)
participants = list()
for opponent in match['opponents']:
participant = toornament.get_participant(tournament_id, opponent['participant']['id'])
summoner_names = list()
for player in participant['lineup']:
summoner_names.append(player['custom_fields']['summoner_name'])
multilink_params = {
'query': ','.join(summoner_names)
}
participant['opgg_multilink'] = urllib.parse.urlencode(multilink_params)
participants.append(participant)
return render_template('match.html', match=match, participants=participants, tournament=tournament)