From 37ae2cf6635edb770dd595e095caa55dcce591c9 Mon Sep 17 00:00:00 2001 From: Stephen McQuay Date: Tue, 23 Apr 2013 23:06:24 -0700 Subject: [PATCH 1/2] streamlined the look --- static/math.css | 14 -------------- static/math.js | 13 +++++++++---- templates/index.html | 13 +++++-------- 3 files changed, 14 insertions(+), 26 deletions(-) diff --git a/static/math.css b/static/math.css index d64b604..2037bda 100644 --- a/static/math.css +++ b/static/math.css @@ -1,21 +1,7 @@ .number { - font-size: 100px; - height: 80px; font-family: helvetica; } -.question { - padding-left: 30px; -} - -.answer { - padding-top: 30px; -} - -#content { - padding-top: 30px; -} - .wrong { background: red; } diff --git a/static/math.js b/static/math.js index 9d99d22..ad34141 100644 --- a/static/math.js +++ b/static/math.js @@ -18,19 +18,24 @@ function deal_with_answer(e) { "second": $("#second").text(), "answer": $("#answer").val(), }; - console.log(data); $.post("/api/v0/attempt/", data, function(d) { if(d["status"]) { - $("#content").removeClass("wrong"); + $("body").removeClass("wrong"); new_problem(); } else { - $("#content").addClass("wrong"); + $("body").addClass("wrong"); + $("#answer").val(""); } + $("#answer").focus(); }); } $(function() { new_problem(); - $("#check").click(deal_with_answer); + $("#answer").keypress(function(e) { + if( e.which == 13) { + deal_with_answer(e); + } + }); }); diff --git a/templates/index.html b/templates/index.html index 75bf2aa..f2bc75c 100644 --- a/templates/index.html +++ b/templates/index.html @@ -7,14 +7,11 @@
-
- 0 - + - 0 -
-
-
- + 0 + + + 0 +
+
From dc24ed7e4acea4e6066ccd6e829bea384885d2b2 Mon Sep 17 00:00:00 2001 From: Stephen McQuay Date: Tue, 23 Apr 2013 23:27:30 -0700 Subject: [PATCH 2/2] added score --- mmg/settings.py | 2 ++ mmg/views.py | 16 +++++++++++----- static/math.js | 5 +++-- templates/index.html | 3 +++ 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/mmg/settings.py b/mmg/settings.py index d4f571f..ec06e6f 100644 --- a/mmg/settings.py +++ b/mmg/settings.py @@ -118,6 +118,8 @@ INSTALLED_APPS = ( # 'django.contrib.admindocs', ) +SESSION_ENGINE = 'django.contrib.sessions.backends.signed_cookies' + # A sample logging configuration. The only tangible logging # performed by this configuration is to send an email to # the site admins on every HTTP 500 error when DEBUG=False. diff --git a/mmg/views.py b/mmg/views.py index 244b826..75ae824 100644 --- a/mmg/views.py +++ b/mmg/views.py @@ -28,7 +28,6 @@ def _generate_problem(): def _validate_solution(a): - print a f = int(a['first']) o = a['operation'] s = int(a['second']) @@ -49,13 +48,20 @@ def home(request): def attempt(request): + print(dict(request.session)) d = request.POST.dict() + r = _validate_solution(d) + if r: + s = request.session.get('score', 0) + 1 + else: + s = request.session.get('score', 0) - 1 + request.session['score'] = s return HttpResponse( - json.dumps({'status': _validate_solution(d)}), + json.dumps({'status': r, 'score': s}), content_type="application/json") def problem(request): - return HttpResponse( - json.dumps(_generate_problem()), - content_type="application/json") + d = _generate_problem() + d['score'] = request.session.get('score', 0) + return HttpResponse(json.dumps(d), content_type="application/json") diff --git a/static/math.js b/static/math.js index ad34141..1cfb180 100644 --- a/static/math.js +++ b/static/math.js @@ -1,12 +1,13 @@ -function update_board(f, o, s) { +function update_board(f, o, s, score) { $("#first").text(f); $("#operation").text(o); $("#second").text(s); + $("#score").text(score); } function new_problem() { $.get("/api/v0/problem/", function(d) { - update_board(d["first"], d["operation"], d["second"]); + update_board(d["first"], d["operation"], d["second"], d["score"]); $("#answer").val(""); }) } diff --git a/templates/index.html b/templates/index.html index f2bc75c..1367d1d 100644 --- a/templates/index.html +++ b/templates/index.html @@ -14,6 +14,9 @@ +
+ score: +