Matchplan/flaskapp/blueprints/tournament.py

53 lines
2.4 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'])
generate_multilink = False
if 'summoner_name' in participant['lineup'][0]['custom_fields']:
generate_multilink = True
elif 'beschwoerername' in participant['lineup'][0]['custom_fields']:
for idx, _ in enumerate(participant['lineup']):
participant['lineup'][idx]['custom_fields']['summoner_name'] = \
participant['lineup'][0]['custom_fields']
generate_multilink = True
elif participant['lineup'][0]['custom_fields'] == {}:
for idx, _ in enumerate(participant['lineup']):
participant['lineup'][idx]['custom_fields']['summoner_name'] = \
participant['lineup'][idx]['name']
generate_multilink = True
else:
for idx, _ in enumerate(participant['lineup']):
participant['lineup'][idx]['custom_fields']['summoner_name'] = 'N/V'
if generate_multilink:
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)