Skip to content

Commit

Permalink
Option to download player email addresses as CSV
Browse files Browse the repository at this point in the history
Feature request in #1
  • Loading branch information
ceari committed Dec 1, 2013
1 parent b6b8d3f commit 8b9e495
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
1 change: 1 addition & 0 deletions whyattend/templates/admin.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
<h2>Administration</h2>
<ul>
{% if g.player.name in g.ADMINS %}<li><a href="{{ url_for('sync_players', clan_id=g.clan_ids[g.player.clan]) }}?API_KEY={{ API_KEY }}">Trigger Clan Synchronisation</a> (wait for the page to load, can take a minute)</li>{% endif %}
<li><a href="{{url_for('export_emails', clan=g.player.clan)}}">Export player e-mail addresses (CSV)</a></li>
</ul>
{% endblock %}
28 changes: 26 additions & 2 deletions whyattend/webapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,23 @@
Implementation of all request handlers and core functionality.
"""

import csv
import datetime
import os
import pickle
import logging
import hashlib
import StringIO

from collections import defaultdict
from functools import wraps
from flask import Flask, g, session, render_template, flash, redirect, request, url_for, abort, make_response, jsonify
from flask import Response
from flask_openid import OpenID
from flask_cache import Cache
from sqlalchemy import or_
from sqlalchemy.orm import joinedload, joinedload_all
from werkzeug.utils import secure_filename
from werkzeug.utils import secure_filename, Headers

from . import config, replays, wotapi, util, tasks, constants
from .model import Player, Battle, BattleAttendance, Replay, BattleGroup, db_session
Expand Down Expand Up @@ -1294,6 +1297,7 @@ def player_performance(clan):
import math
min = lambda a, b: a if a <= b else b


wn7 = defaultdict(float)
for p in clan_players:
if battle_count[p] == 0: continue
Expand All @@ -1319,4 +1323,24 @@ def profile():
g.player.email = request.form.get('email', '')
db_session.add(g.player)
db_session.commit()
return render_template('players/profile.html')
return render_template('players/profile.html')


@app.route('/admin/export-emails/<clan>')
@require_login
@require_clan_membership
@require_role(config.ADMIN_ROLES)
def export_emails(clan):
csv_response = StringIO.StringIO()
csv_writer = csv.writer(csv_response)
csv_writer.writerow(["Name", "e-mail"])

for player in Player.query.filter_by(locked=False, clan=clan).order_by('email'):
csv_writer.writerow([player.name, player.email])

csv_response.seek(0)
headers = Headers()
headers.add('Content-Type', 'text/csv')
headers.add('Content-Disposition', 'attachment',
filename=secure_filename(clan + "_emails.csv"))
return Response(response=csv_response.read(), headers=headers)

0 comments on commit 8b9e495

Please sign in to comment.