Skip to content

Commit

Permalink
Admin tool to delete malformed matches.
Browse files Browse the repository at this point in the history
  • Loading branch information
gregmarra committed Apr 24, 2012
1 parent cbc4520 commit 16ee6b0
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 1 deletion.
3 changes: 2 additions & 1 deletion admin_main.py
Expand Up @@ -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

Expand All @@ -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),
Expand Down
28 changes: 28 additions & 0 deletions controllers/admin/admin_match_controller.py
Expand Up @@ -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
Expand Down
26 changes: 26 additions & 0 deletions templates/admin/matches/cleanup.html
@@ -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 %}
2 changes: 2 additions & 0 deletions templates/admin/matches/dashboard.html
Expand Up @@ -8,5 +8,7 @@ <h1>Matches</h1>
<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.