Skip to content

Commit

Permalink
Create a page for admins to enter maps for the week
Browse files Browse the repository at this point in the history
  • Loading branch information
dreiss committed Feb 5, 2012
1 parent 1e8c282 commit 61a27a4
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 10 deletions.
58 changes: 58 additions & 0 deletions ahgl_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def debug_page():
@app.route("/")
def home_page():
return flask.render_template("home.html", links=dict(
enter_maps = flask.url_for(enter_maps.__name__),
show_lineup = flask.url_for(show_lineup_select.__name__),
enter_lineup = flask.url_for(enter_lineup.__name__),
show_result = flask.url_for(show_result_select.__name__),
Expand Down Expand Up @@ -111,6 +112,63 @@ def logout():
return flask.redirect(flask.url_for(home_page.__name__))


@app.route("/enter-maps")
@require_auth
@require_admin
def enter_maps():
with contextlib.closing(g.db.cursor()) as cursor:
cursor.execute("SELECT MAX(week) FROM maps")
week_number = (list(cursor)[0][0] or 0) + 1
with contextlib.closing(g.db.cursor()) as cursor:
cursor.execute("SELECT id, mapname FROM mapnames")
map_pool = list(cursor)
return flask.render_template("enter_maps.html",
week_number = week_number,
num_sets = 5,
map_pool = map_pool,
submit_link = flask.url_for(submit_maps.__name__),
)


@app.route("/submit-maps", methods=["POST"])
@require_auth
@require_admin
def submit_maps():
postdata = flask.request.form

week_number = postdata.getlist("week")
if len(week_number) != 1 or not week_number[0]:
return "No value submitted for 'week'"
week_number = week_number[0]
try:
week_number = int(week_number)
except ValueError:
return "Invalid week"

with contextlib.closing(g.db.cursor()) as cursor:
cursor.execute("SELECT COUNT(*) FROM maps WHERE week = ?", (week_number,))
if list(cursor) != [(0,)]:
return "Maps already submitted"

for setnum in range(1,5+1):
mapid = postdata.get("map_%d" % setnum)
if not mapid:
return "No value submitted for 'map_%d'" % setnum
try:
mapid = int(mapid)
except ValueError:
return "Invalid map"
with contextlib.closing(g.db.cursor()) as cursor:
cursor.execute(
"INSERT INTO maps(week, set_number, mapid) "
"VALUES (?,?,?) "
, (week_number, setnum, mapid))

g.db.commit()

return flask.render_template("success.html", item_type="Maps")


@app.route("/show-lineup")
def show_lineup_select():
with contextlib.closing(g.db.cursor()) as cursor:
Expand Down
24 changes: 24 additions & 0 deletions templates/enter_maps.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html>
<head>
<title>AHGL Map Entry</title>
</head>
<body>
<h1>AHGL Map Entry</h1>
<h2>Week {{week_number}}</h2>
<form method="POST" action="{{submit_link}}">
<input type="hidden" name="week" value="{{week_number}}" />
<ul>
{% for setnum in range(1,num_sets+1) %}
<li>Map {{setnum}}:
<select name="map_{{setnum}}">
{% for mapid, mapname in map_pool %}
<option value="{{mapid}}">{{mapname}}</option>
{% endfor %}
</select><br>
{% endfor %}
</ul>
<input type="submit">
</form>
</body>
</html>
1 change: 1 addition & 0 deletions templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<body>
<h1>AHGL Admin Page</h1>
<ul>
<li><a href="{{links.enter_maps}}">Enter Maps</a>
<li><a href="{{links.show_lineup}}">Show Lineup</a>
<li><a href="{{links.enter_lineup}}">Enter Lineup</a>
<li><a href="{{links.show_result}}">Show Result</a>
Expand Down
10 changes: 0 additions & 10 deletions test_data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,3 @@ INSERT INTO "mapnames" VALUES(4, 'Shattered Temple');
INSERT INTO "mapnames" VALUES(5, 'Tal''Darim Altar');
INSERT INTO "mapnames" VALUES(6, 'Typhon Peaks');
INSERT INTO "mapnames" VALUES(7, 'Xel''Naga Caverns');
INSERT INTO "maps" VALUES(1,1,7);
INSERT INTO "maps" VALUES(1,2,5);
INSERT INTO "maps" VALUES(1,3,1);
INSERT INTO "maps" VALUES(1,4,2);
INSERT INTO "maps" VALUES(1,5,4);
INSERT INTO "maps" VALUES(2,1,3);
INSERT INTO "maps" VALUES(2,2,7);
INSERT INTO "maps" VALUES(2,3,6);
INSERT INTO "maps" VALUES(2,4,2);
INSERT INTO "maps" VALUES(2,5,5);
34 changes: 34 additions & 0 deletions webdriver_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ def login(team):
auth_key = list(cursor)[0][0]
wd.get(bu + 'login/' + auth_key)

def login_admin():
with contextlib.closing(db_conn.cursor()) as cursor:
cursor.execute(
'SELECT auth_key FROM accounts WHERE team = -1')
auth_key = list(cursor)[0][0]
wd.get(bu + 'login/' + auth_key)

wd.find_element_by_link_text('Enter Lineup').click()
wait_title('No Account')
wd.get(bu)
Expand All @@ -93,6 +100,23 @@ def login(team):
wait_title('No Account')
wd.get(bu)

def enter_maps(week, mapnames):
login_admin()
wd.find_element_by_link_text('Enter Maps').click()
wait_title('AHGL Map Entry')

self.assertEqual(css('h1').text, 'AHGL Map Entry')
self.assertEqual(css('h2').text, 'Week %d' % week)
for number, mapname in enumerate(mapnames):
Select(css('select[name=map_%d]' % (number+1))).select_by_visible_text(mapname)

css('input[type=submit]').submit()
WebDriverWait(wd, 1).until(lambda w: w.title != 'AHGL Map Entry')

self.assertEqual(wd.title, 'Success')
wd.get(bu)


def enter_lineup(week, team, players):
login(team)
wd.find_element_by_link_text('Enter Lineup').click()
Expand All @@ -111,6 +135,16 @@ def enter_lineup(week, team, players):
self.assertEqual(wd.title, 'Success')
wd.get(bu)


enter_maps(1, [
"Xel'Naga Caverns",
"Tal'Darim Altar",
"Backwater Gulch",
"Metalopolis",
"Shattered Temple",
])


if not os.environ.get("TEST_SKIP_LINEUP"):
enter_lineup(1, 'Twitter', [
('implausible.931', 'P'),
Expand Down

0 comments on commit 61a27a4

Please sign in to comment.