From 16ee6b09f6bdc713d1b0fb40dfe3d1776b357bab Mon Sep 17 00:00:00 2001 From: Greg Marra Date: Mon, 23 Apr 2012 23:14:15 -0700 Subject: [PATCH] Admin tool to delete malformed matches. --- admin_main.py | 3 ++- controllers/admin/admin_match_controller.py | 28 +++++++++++++++++++++ templates/admin/matches/cleanup.html | 26 +++++++++++++++++++ templates/admin/matches/dashboard.html | 2 ++ 4 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 templates/admin/matches/cleanup.html diff --git a/admin_main.py b/admin_main.py index 8cbf7b4d65..8103ccff90 100644 --- a/admin_main.py +++ b/admin_main.py @@ -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), diff --git a/controllers/admin/admin_match_controller.py b/controllers/admin/admin_match_controller.py index fe1963d057..84656a9973 100644 --- a/controllers/admin/admin_match_controller.py +++ b/controllers/admin/admin_match_controller.py @@ -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 diff --git a/templates/admin/matches/cleanup.html b/templates/admin/matches/cleanup.html new file mode 100644 index 0000000000..ba6521f7ce --- /dev/null +++ b/templates/admin/matches/cleanup.html @@ -0,0 +1,26 @@ +{% extends "admin/base.html" %} + +{% block title %}Match Dashboard - TBA Admin{% endblock %} + +{% block content %} + +

Clean up Matches

+ +{% if tried_delete %} +

Deleted {{ match_keys_deleted|length }} malformed matches: {{ match_keys_deleted }}

+{% endif %} + +

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").

+ +
+
+ Clean up what Event? (like 2011new) +
    +
  • +
  • +
+
+
+ + +{% endblock %} \ No newline at end of file diff --git a/templates/admin/matches/dashboard.html b/templates/admin/matches/dashboard.html index 4934273550..5be61f0fcd 100644 --- a/templates/admin/matches/dashboard.html +++ b/templates/admin/matches/dashboard.html @@ -8,5 +8,7 @@

Matches

{{ match_count }} total matches

Edit with: admin/match/edit/{match_key}

+

Match Cleanup

+ {% endblock %} \ No newline at end of file