From 18b96e6f5fef6f7dabb531e799c67cc173f834be Mon Sep 17 00:00:00 2001 From: Ant Zucaro Date: Tue, 17 Jun 2014 21:30:37 -0400 Subject: [PATCH] Add flash messaging. Failures do not work yet. --- xonstat/templates/merge.mako | 20 ++++++++++++++++++++ xonstat/views/admin.py | 10 ++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/xonstat/templates/merge.mako b/xonstat/templates/merge.mako index 9704f21..d1fc10f 100644 --- a/xonstat/templates/merge.mako +++ b/xonstat/templates/merge.mako @@ -9,6 +9,26 @@ ${nav.nav('players')}

Merge two players below.

+% if len(request.session.peek_flash("failure")) > 0: +
+
+
+ + ${request.session.pop_flash("failure")[0]} +
+
+
+% endif + +% if len(request.session.peek_flash("success")) > 0: +
+
+ + ${request.session.pop_flash("success")[0]} +
+
+% endif +
diff --git a/xonstat/views/admin.py b/xonstat/views/admin.py index 520f779..8d5c20c 100644 --- a/xonstat/views/admin.py +++ b/xonstat/views/admin.py @@ -41,8 +41,6 @@ def merge(request): if request.params.has_key("csrf_token"): # check the token to prevent request forgery st = request.session.get_csrf_token() - log.debug("Session token is %s" % st) - log.debug("Request token is %s" % request.params.get('csrf_token')) check_csrf_token(request) if request.params.has_key("w_pid") and request.params.has_key("l_pid"): @@ -56,7 +54,15 @@ def merge(request): s.commit() + request.session.flash( + "Successfully merged player %s into %s!" % (l_pid, w_pid), + "success") + except: s.rollback() + request.session.flash( + "Could not merge player %s into %s." % (l_pid, w_pid), + "failure") + return {} -- 2.39.2