Now using query string instead of dedicated route.

This commit is contained in:
neviyn 2015-11-17 18:47:00 +00:00
parent 25d916d4a0
commit 231b4231a3
4 changed files with 11 additions and 11 deletions

View File

@ -35,6 +35,7 @@ updateQuizItemStats = () ->
$('#radical-num').text(sessionStorage.getItem('radical_count')); $('#radical-num').text(sessionStorage.getItem('radical_count'));
$('#kanji-num').text(sessionStorage.getItem('kanji_count')); $('#kanji-num').text(sessionStorage.getItem('kanji_count'));
$('#vocab-num').text(sessionStorage.getItem('vocabulary_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 = () -> filterQuestions = () ->
input_data = $('#filter-input').val() input_data = $('#filter-input').val()
@ -43,7 +44,7 @@ filterQuestions = () ->
sessionStorage.removeItem('radical_count') sessionStorage.removeItem('radical_count')
sessionStorage.removeItem('kanji_count') sessionStorage.removeItem('kanji_count')
sessionStorage.removeItem('vocabulary_count') sessionStorage.removeItem('vocabulary_count')
target_url = "/user_items/" + input_data target_url = "/user_items?level_range=" + input_data
$.ajax $.ajax
url: target_url, url: target_url,
dataType: 'json', dataType: 'json',

View File

@ -45,7 +45,8 @@
updateQuizItemStats = function() { updateQuizItemStats = function() {
$('#radical-num').text(sessionStorage.getItem('radical_count')); $('#radical-num').text(sessionStorage.getItem('radical_count'));
$('#kanji-num').text(sessionStorage.getItem('kanji_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() { filterQuestions = function() {
@ -56,7 +57,7 @@
sessionStorage.removeItem('radical_count'); sessionStorage.removeItem('radical_count');
sessionStorage.removeItem('kanji_count'); sessionStorage.removeItem('kanji_count');
sessionStorage.removeItem('vocabulary_count'); sessionStorage.removeItem('vocabulary_count');
target_url = "/user_items/" + input_data; target_url = "/user_items?level_range=" + input_data;
return $.ajax({ return $.ajax({
url: target_url, url: target_url,
dataType: 'json', dataType: 'json',

View File

@ -38,6 +38,7 @@
<li><span id="radical-num"></span> Radicals</li> <li><span id="radical-num"></span> Radicals</li>
<li><span id="kanji-num"></span> Kanji</li> <li><span id="kanji-num"></span> Kanji</li>
<li><span id="vocab-num"></span> Vocabulary</li> <li><span id="vocab-num"></span> Vocabulary</li>
<li><span id="total-num"></span> Total</li>
</ul> </ul>
</li> </li>
<li id="api-refresh" class="navbar-text" data-toggle="tooltip" data-placement="bottom" title="Last API Refresh: {{ current_user.last_updated|datetime_format }}. Click to refresh."><span><img alt="avatar" src="http://www.gravatar.com/avatar/{{ current_user.gravatar }}?s=24"></span> {{ current_user.username }}</li> <li id="api-refresh" class="navbar-text" data-toggle="tooltip" data-placement="bottom" title="Last API Refresh: {{ current_user.last_updated|datetime_format }}. Click to refresh."><span><img alt="avatar" src="http://www.gravatar.com/avatar/{{ current_user.gravatar }}?s=24"></span> {{ current_user.username }}</li>

View File

@ -1,5 +1,5 @@
import json, re 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.login import LoginManager, login_user, login_required, current_user, logout_user, login_fresh
from flask.ext.sqlalchemy import SQLAlchemy from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext.wtf import Form from flask.ext.wtf import Form
@ -181,13 +181,10 @@ def show_quiz():
@app.route('/user_items') @app.route('/user_items')
@login_required @login_required
def get_items(): def get_items():
return get_items_with_level_restriction(list(range(0, 61))) level_range = list(range(0, 61))
if request.args.get('level_range'):
level_range = parse_range(request.args.get('level_range'))
@app.route('/user_items/<level_range>') return get_items_with_level_restriction(level_range)
@login_required
def get_items_with_range(level_range):
return get_items_with_level_restriction(parse_range(level_range))
@app.route('/refresh', methods=['POST']) @app.route('/refresh', methods=['POST'])