from flask import Blueprint, render_template, request from flaskapp.lib.toornament import get_toornament import urllib.parse bp = Blueprint('tournament', __name__) @bp.route('/tournament/') 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//match/') 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']) if 'summoner_name' in participant['lineup'][0]['custom_fields']: 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) else: for idx, _ in enumerate(participant['lineup']): participant['lineup'][idx]['custom_fields']['summoner_name'] = 'N/V' participants.append(participant) return render_template('match.html', match=match, participants=participants, tournament=tournament)