Matchplan/flaskapp/blueprints/tournament.py

40 lines
1.7 KiB
Python
Raw Normal View History

2021-05-08 05:29:32 +02:00
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'])
2021-05-08 06:40:33 +02:00
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'
2021-05-08 05:29:32 +02:00
participants.append(participant)
return render_template('match.html', match=match, participants=participants, tournament=tournament)