Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Admin tool to delete malformed matches.

  • Loading branch information...
commit 16ee6b09f6bdc713d1b0fb40dfe3d1776b357bab 1 parent cbc4520
Greg Marra authored
3  admin_main.py
@@ -14,7 +14,7 @@
14 14
15 15 from controllers.admin.admin_event_controller import AdminEventDetail, AdminEventEdit, AdminEventList
16 16 from controllers.admin.admin_main_controller import AdminDebugHandler, AdminMain
17   -from controllers.admin.admin_match_controller import AdminMatchAddVideos, AdminMatchDashboard, AdminMatchDetail, AdminMatchEdit
  17 +from controllers.admin.admin_match_controller import AdminMatchAddVideos, AdminMatchCleanup, AdminMatchDashboard, AdminMatchDetail, AdminMatchEdit
18 18 from controllers.admin.admin_memcache_controller import AdminMemcacheMain, AdminMemcacheFlush
19 19 from controllers.admin.admin_team_controller import AdminTeamDetail, AdminTeamList
20 20
@@ -27,6 +27,7 @@ def main():
27 27 ('/admin/event/(.*)', AdminEventDetail),
28 28 ('/admin/match/', AdminMatchDashboard),
29 29 ('/admin/match/addvideos', AdminMatchAddVideos),
  30 + ('/admin/match/cleanup', AdminMatchCleanup),
30 31 ('/admin/match/edit/(.*)', AdminMatchEdit),
31 32 ('/admin/match/(.*)', AdminMatchDetail),
32 33 ('/admin/memcache/', AdminMemcacheMain),
28 controllers/admin/admin_match_controller.py
@@ -9,6 +9,34 @@
9 9 from models import Match, Event
10 10 from helpers.match_helper import MatchUpdater
11 11
  12 +class AdminMatchCleanup(webapp.RequestHandler):
  13 + """
  14 + Given an Event, clean up all Matches that don't have the Event's key as their key prefix.
  15 + Used to clean up 2011 Matches, where we had dupes of "2011new_qm1" and "2011newton_qm1".
  16 + """
  17 + def get(self):
  18 + path = os.path.join(os.path.dirname(__file__), '../../templates/admin/matches/cleanup.html')
  19 + self.response.out.write(template.render(path, {}))
  20 +
  21 + def post(self):
  22 + event = Event.get_by_key_name(self.request.get("event_key_name"))
  23 + matches_to_delete = list()
  24 + match_keys_to_delete = list()
  25 + for match in event.match_set:
  26 + if match.key().name() != match.get_key_name():
  27 + matches_to_delete.append(match)
  28 + match_keys_to_delete.append(match.key().name())
  29 +
  30 + db.delete(matches_to_delete)
  31 +
  32 + template_values = {
  33 + "match_keys_deleted": match_keys_to_delete,
  34 + "tried_delete": True
  35 + }
  36 +
  37 + path = os.path.join(os.path.dirname(__file__), '../../templates/admin/matches/cleanup.html')
  38 + self.response.out.write(template.render(path, template_values))
  39 +
12 40 class AdminMatchDashboard(webapp.RequestHandler):
13 41 """
14 42 Show stats about Matches
26 templates/admin/matches/cleanup.html
... ... @@ -0,0 +1,26 @@
  1 +{% extends "admin/base.html" %}
  2 +
  3 +{% block title %}Match Dashboard - TBA Admin{% endblock %}
  4 +
  5 +{% block content %}
  6 +
  7 +<h1>Clean up Matches</h1>
  8 +
  9 +{% if tried_delete %}
  10 +<p><strong>Deleted {{ match_keys_deleted|length }} malformed matches:</strong> {{ match_keys_deleted }}</p>
  11 +{% endif %}
  12 +
  13 +<p>This page deletes all Matches belonging to an Event where the Match key names don't correspond to the Event key name. This will delete ("Match", "2011newton_f1m1") from ("Event", "2011new"), but will leave ("Match", "2011new_f1m1").</p>
  14 +
  15 +<form action="/admin/match/cleanup" method="post">
  16 + <fieldset>
  17 + <legend>Clean up what Event? (like 2011new)</legend>
  18 + <ul>
  19 + <li><input type="text" name="event_key_name" /><label for="event_key_name">Event Key</label></li>
  20 + <li><input type="submit" id="submit" name="submit" value="Clean Up"></li>
  21 + </ul>
  22 + </fieldset>
  23 +</form>
  24 +
  25 +
  26 +{% endblock %}
2  templates/admin/matches/dashboard.html
@@ -8,5 +8,7 @@
8 8 <p>{{ match_count }} total matches</p>
9 9 <p>Edit with: <strong>admin/match/edit/{match_key}</strong></p>
10 10
  11 +<p><a href="/admin/match/cleanup">Match Cleanup</a></p>
  12 +
11 13
12 14 {% endblock %}

0 comments on commit 16ee6b0

Please sign in to comment.
Something went wrong with that request. Please try again.