From 231b4231a3969d75f4509fac907d9785f5e617a3 Mon Sep 17 00:00:00 2001 From: Nathan Cannon Date: Tue, 17 Nov 2015 18:47:00 +0000 Subject: [PATCH] Now using query string instead of dedicated route. --- static/quiz_item.coffee | 3 ++- static/quiz_item.js | 5 +++-- templates/quiz.html | 1 + wanikaniburned.py | 13 +++++-------- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/static/quiz_item.coffee b/static/quiz_item.coffee index 78f1211..e340672 100644 --- a/static/quiz_item.coffee +++ b/static/quiz_item.coffee @@ -35,6 +35,7 @@ updateQuizItemStats = () -> $('#radical-num').text(sessionStorage.getItem('radical_count')); $('#kanji-num').text(sessionStorage.getItem('kanji_count')); $('#vocab-num').text(sessionStorage.getItem('vocabulary_count')); + $('#total-num').text(parseInt(sessionStorage.getItem('radical_count')) + parseInt(sessionStorage.getItem('kanji_count'))+ parseInt(sessionStorage.getItem('vocabulary_count'))) filterQuestions = () -> input_data = $('#filter-input').val() @@ -43,7 +44,7 @@ filterQuestions = () -> sessionStorage.removeItem('radical_count') sessionStorage.removeItem('kanji_count') sessionStorage.removeItem('vocabulary_count') - target_url = "/user_items/" + input_data + target_url = "/user_items?level_range=" + input_data $.ajax url: target_url, dataType: 'json', diff --git a/static/quiz_item.js b/static/quiz_item.js index c1fb596..00d8444 100644 --- a/static/quiz_item.js +++ b/static/quiz_item.js @@ -45,7 +45,8 @@ updateQuizItemStats = function() { $('#radical-num').text(sessionStorage.getItem('radical_count')); $('#kanji-num').text(sessionStorage.getItem('kanji_count')); - return $('#vocab-num').text(sessionStorage.getItem('vocabulary_count')); + $('#vocab-num').text(sessionStorage.getItem('vocabulary_count')); + return $('#total-num').text(parseInt(sessionStorage.getItem('radical_count')) + parseInt(sessionStorage.getItem('kanji_count')) + parseInt(sessionStorage.getItem('vocabulary_count'))); }; filterQuestions = function() { @@ -56,7 +57,7 @@ sessionStorage.removeItem('radical_count'); sessionStorage.removeItem('kanji_count'); sessionStorage.removeItem('vocabulary_count'); - target_url = "/user_items/" + input_data; + target_url = "/user_items?level_range=" + input_data; return $.ajax({ url: target_url, dataType: 'json', diff --git a/templates/quiz.html b/templates/quiz.html index 4dff007..7ef93fb 100644 --- a/templates/quiz.html +++ b/templates/quiz.html @@ -38,6 +38,7 @@
  • Radicals
  • Kanji
  • Vocabulary
  • +
  • Total
  • diff --git a/wanikaniburned.py b/wanikaniburned.py index d5cbf70..a9b3df8 100644 --- a/wanikaniburned.py +++ b/wanikaniburned.py @@ -1,5 +1,5 @@ import json, re -from flask import Flask, render_template, redirect, url_for, jsonify, flash +from flask import Flask, render_template, redirect, url_for, jsonify, flash, request from flask.ext.login import LoginManager, login_user, login_required, current_user, logout_user, login_fresh from flask.ext.sqlalchemy import SQLAlchemy from flask.ext.wtf import Form @@ -181,13 +181,10 @@ def show_quiz(): @app.route('/user_items') @login_required def get_items(): - return get_items_with_level_restriction(list(range(0, 61))) - - -@app.route('/user_items/') -@login_required -def get_items_with_range(level_range): - return get_items_with_level_restriction(parse_range(level_range)) + level_range = list(range(0, 61)) + if request.args.get('level_range'): + level_range = parse_range(request.args.get('level_range')) + return get_items_with_level_restriction(level_range) @app.route('/refresh', methods=['POST'])