Permalink
Browse files

Admin tool to delete malformed matches.

  • Loading branch information...
1 parent cbc4520 commit 16ee6b09f6bdc713d1b0fb40dfe3d1776b357bab @gregmarra committed Apr 24, 2012
View
@@ -14,7 +14,7 @@
from controllers.admin.admin_event_controller import AdminEventDetail, AdminEventEdit, AdminEventList
from controllers.admin.admin_main_controller import AdminDebugHandler, AdminMain
-from controllers.admin.admin_match_controller import AdminMatchAddVideos, AdminMatchDashboard, AdminMatchDetail, AdminMatchEdit
+from controllers.admin.admin_match_controller import AdminMatchAddVideos, AdminMatchCleanup, AdminMatchDashboard, AdminMatchDetail, AdminMatchEdit
from controllers.admin.admin_memcache_controller import AdminMemcacheMain, AdminMemcacheFlush
from controllers.admin.admin_team_controller import AdminTeamDetail, AdminTeamList
@@ -27,6 +27,7 @@ def main():
('/admin/event/(.*)', AdminEventDetail),
('/admin/match/', AdminMatchDashboard),
('/admin/match/addvideos', AdminMatchAddVideos),
+ ('/admin/match/cleanup', AdminMatchCleanup),
('/admin/match/edit/(.*)', AdminMatchEdit),
('/admin/match/(.*)', AdminMatchDetail),
('/admin/memcache/', AdminMemcacheMain),
@@ -9,6 +9,34 @@
from models import Match, Event
from helpers.match_helper import MatchUpdater
+class AdminMatchCleanup(webapp.RequestHandler):
+ """
+ Given an Event, clean up all Matches that don't have the Event's key as their key prefix.
+ Used to clean up 2011 Matches, where we had dupes of "2011new_qm1" and "2011newton_qm1".
+ """
+ def get(self):
+ path = os.path.join(os.path.dirname(__file__), '../../templates/admin/matches/cleanup.html')
+ self.response.out.write(template.render(path, {}))
+
+ def post(self):
+ event = Event.get_by_key_name(self.request.get("event_key_name"))
+ matches_to_delete = list()
+ match_keys_to_delete = list()
+ for match in event.match_set:
+ if match.key().name() != match.get_key_name():
+ matches_to_delete.append(match)
+ match_keys_to_delete.append(match.key().name())
+
+ db.delete(matches_to_delete)
+
+ template_values = {
+ "match_keys_deleted": match_keys_to_delete,
+ "tried_delete": True
+ }
+
+ path = os.path.join(os.path.dirname(__file__), '../../templates/admin/matches/cleanup.html')
+ self.response.out.write(template.render(path, template_values))
+
class AdminMatchDashboard(webapp.RequestHandler):
"""
Show stats about Matches
@@ -0,0 +1,26 @@
+{% extends "admin/base.html" %}
+
+{% block title %}Match Dashboard - TBA Admin{% endblock %}
+
+{% block content %}
+
+<h1>Clean up Matches</h1>
+
+{% if tried_delete %}
+<p><strong>Deleted {{ match_keys_deleted|length }} malformed matches:</strong> {{ match_keys_deleted }}</p>
+{% endif %}
+
+<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>
+
+<form action="/admin/match/cleanup" method="post">
+ <fieldset>
+ <legend>Clean up what Event? (like 2011new)</legend>
+ <ul>
+ <li><input type="text" name="event_key_name" /><label for="event_key_name">Event Key</label></li>
+ <li><input type="submit" id="submit" name="submit" value="Clean Up"></li>
+ </ul>
+ </fieldset>
+</form>
+
+
+{% endblock %}
@@ -8,5 +8,7 @@
<p>{{ match_count }} total matches</p>
<p>Edit with: <strong>admin/match/edit/{match_key}</strong></p>
+<p><a href="/admin/match/cleanup">Match Cleanup</a></p>
+
{% endblock %}

0 comments on commit 16ee6b0

Please sign in to comment.