Skip to content

Commit

Permalink
Add link to add battle to battle group page
Browse files Browse the repository at this point in the history
The appropriate battle group will be preselected.

Warn if uploaded replays are missing the "pickle" part, i.e. where the
battle duration cannot be determined automatically and which cannot be
used in player performance calculation

Link from battle groups was a feature request in #1
  • Loading branch information
ceari committed Dec 11, 2013
1 parent 9404146 commit f6c1591
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
5 changes: 5 additions & 0 deletions whyattend/templates/battles/battle_group.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ <h2>Battle group: {{battle_group.title}}</h2>
</dl>
{% endif %}
<hr>
{% if g.player and (g.player.role in g.CREATE_BATTLE_ROLES or g.player.name in g.ADMINS) %}
<div style="margin-bottom: 1em;">
<a class="btn btn-small btn-primary" href="{{url_for('create_battle_from_replay', battle_group_id=battle_group.id)}}">Add Battle To Group</a>
</div>
{% endif %}
<table id="battles" class="table table-striped">
<thead>
<tr>
Expand Down
2 changes: 1 addition & 1 deletion whyattend/templates/battles/create.html
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ <h2>Add battle</h2>
<option value="-2">Not in a group</option>
<option value="-1">Create a new group</option>
{% for battle_group in battle_groups %}
<option value="{{battle_group.id}}">{{battle_group.date.strftime('%d.%m.%Y %H:%M:%S')}} - {{battle_group.title}}</option>
<option value="{{battle_group.id}}" {{'selected' if battle_group.id==battle_group_id else ''}}>{{battle_group.date.strftime('%d.%m.%Y %H:%M:%S')}} - {{battle_group.title}}</option>
{% endfor %}
</select>
<div id="battle_group_create">
Expand Down
1 change: 1 addition & 0 deletions whyattend/templates/battles/create_from_replay.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ <h2>Add battle</h2>
<input type="file" id="replay" name="replay">
</div>
<input name=_csrf_token type=hidden value="{{ csrf_token() }}">
<input id="battle_group_id" name="battle_group_id" type="hidden" value="{{request.args.get('battle_group_id', -2)}}">
<button type="submit" class="btn btn-success">Click to add this replay</button>
</form>

Expand Down
15 changes: 12 additions & 3 deletions whyattend/webapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,12 +429,16 @@ def create_battle_from_replay():
if request.method == 'POST':
file = request.files['replay']
if file and file.filename.endswith('.wotreplay'):
battle_group_id = int(request.form.get('battle_group_id', -2))
folder = datetime.datetime.now().strftime("%d.%m.%Y")
filename = secure_filename(g.player.name + '_' + file.filename)
if not os.path.exists(os.path.join(app.config['UPLOAD_FOLDER'], folder)):
os.makedirs(os.path.join(app.config['UPLOAD_FOLDER'], folder))
file.save(os.path.join(app.config['UPLOAD_FOLDER'], folder, filename))
return redirect(url_for('create_battle', folder=folder, filename=filename))
if battle_group_id:
return redirect(url_for('create_battle', battle_group_id=battle_group_id, folder=folder, filename=filename))
else:
return redirect(url_for('create_battle', folder=folder, filename=filename))
return render_template('battles/create_from_replay.html')


Expand Down Expand Up @@ -574,7 +578,8 @@ def create_battle():
battle_commander = None
date = datetime.datetime.now()
battle_groups = BattleGroup.query.filter_by(clan=g.player.clan).order_by('date').all()
battle_group = '-1'
battle_group = ''
battle_group_id = int(request.args.get('battle_group_id', -2))
battle_group_title = ''
battle_group_description = ''
battle_group_final = False
Expand Down Expand Up @@ -616,6 +621,10 @@ def create_battle():

if replay['pickle']:
duration = int(replay['pickle']['common']['duration'])
else:
flash('Warning. Replay seems to be incomplete (detailed battle information is missing). '
'Cannot determine battle duration automatically and replay cannot be used in player performance'
' calculation!', 'error')

if request.method == 'POST':
players = map(int, request.form.getlist('players'))
Expand Down Expand Up @@ -722,7 +731,7 @@ def create_battle():
battle_result=battle_result, date=date, battle_groups=battle_groups,
battle_group=battle_group, battle_group_title=battle_group_title, duration=duration,
battle_group_description=battle_group_description, battle_group_final=battle_group_final,
sorted_players=sorted_players)
sorted_players=sorted_players, battle_group_id=battle_group_id)


@app.route('/battles/list/<clan>')
Expand Down

0 comments on commit f6c1591

Please sign in to comment.