Added route for level filtered quiz item list. Removed unused code from quiz_item.coffee.
This commit is contained in:
parent
ff19b0e6b9
commit
b3efe16e3c
@ -51,8 +51,6 @@ $(document).keypress (e) ->
|
|||||||
|
|
||||||
$("#submit-answer").click (e) ->
|
$("#submit-answer").click (e) ->
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
answers = $('#answer').text().split(/[,\.]/g);
|
|
||||||
answers = $.map(answers, (x) -> )
|
|
||||||
input_answer = document.getElementById('kana').value;
|
input_answer = document.getElementById('kana').value;
|
||||||
if($("#kana").hasClass("correct"))
|
if($("#kana").hasClass("correct"))
|
||||||
refreshQuestion();
|
refreshQuestion();
|
||||||
|
@ -67,10 +67,8 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
$("#submit-answer").click(function(e) {
|
$("#submit-answer").click(function(e) {
|
||||||
var answers, input_answer;
|
var input_answer;
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
answers = $('#answer').text().split(/[,\.]/g);
|
|
||||||
answers = $.map(answers, function(x) {});
|
|
||||||
input_answer = document.getElementById('kana').value;
|
input_answer = document.getElementById('kana').value;
|
||||||
if ($("#kana").hasClass("correct")) {
|
if ($("#kana").hasClass("correct")) {
|
||||||
return refreshQuestion();
|
return refreshQuestion();
|
||||||
|
@ -90,6 +90,52 @@ class User(db.Model):
|
|||||||
raise ValueError('Cannot refresh now, try again later.')
|
raise ValueError('Cannot refresh now, try again later.')
|
||||||
|
|
||||||
|
|
||||||
|
def parse_range(input_range):
|
||||||
|
if input_range.match('\d+([,-]\d+)*'):
|
||||||
|
result = []
|
||||||
|
components = input_range.split(',')
|
||||||
|
for item in components:
|
||||||
|
if item.isdigit():
|
||||||
|
result.append(item)
|
||||||
|
else:
|
||||||
|
range_ends = item.split('-')
|
||||||
|
result.extend(list(range(range_ends[0], range_ends[1])))
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def get_items_with_level_restriction(level_range):
|
||||||
|
items = []
|
||||||
|
radical_count = 0
|
||||||
|
for item in json.loads(current_user.radicals):
|
||||||
|
if item['user_specific'] and item['user_specific']['burned'] and item['level'] in level_range:
|
||||||
|
radical_count += 1
|
||||||
|
if item['image']:
|
||||||
|
items.append({'item_type': 'radical', 'question': item['image'], 'answer': item['meaning']})
|
||||||
|
else:
|
||||||
|
items.append({'item_type': 'radical', 'question': item['character'], 'answer': item['meaning']})
|
||||||
|
kanji_count = 0
|
||||||
|
for item in json.loads(current_user.kanji):
|
||||||
|
kanji_count += 1
|
||||||
|
made_answer = ""
|
||||||
|
if item['user_specific'] and item['user_specific']['burned'] and item['level'] in level_range:
|
||||||
|
if item['onyomi'] and item['kunyomi']:
|
||||||
|
made_answer = item['onyomi'] + ',' + item['kunyomi'].replace('.*', '')
|
||||||
|
elif item['onyomi']:
|
||||||
|
made_answer = item['onyomi']
|
||||||
|
elif item['kunyomi']:
|
||||||
|
made_answer = item['kunyomi'].replace('.*', '')
|
||||||
|
items.append({'item_type': 'kanji', 'question': item['character'], 'answer': made_answer,
|
||||||
|
'answer_meaning': item['meaning']})
|
||||||
|
vocabulary_count = 0
|
||||||
|
for item in json.loads(current_user.vocabulary):
|
||||||
|
if item['user_specific'] and item['user_specific']['burned'] and item['level'] in level_range:
|
||||||
|
vocabulary_count += 1
|
||||||
|
items.append({'item_type': 'vocabulary', 'question': item['character'], 'answer': item['kana'],
|
||||||
|
'answer_meaning': item['meaning']})
|
||||||
|
return jsonify(radical_count=radical_count, kanji_count=kanji_count, vocabulary_count=vocabulary_count,
|
||||||
|
item_list=items)
|
||||||
|
|
||||||
|
|
||||||
@login_manager.user_loader
|
@login_manager.user_loader
|
||||||
def load_user(api_key):
|
def load_user(api_key):
|
||||||
return User.query.get(str(api_key))
|
return User.query.get(str(api_key))
|
||||||
@ -131,36 +177,13 @@ def show_quiz():
|
|||||||
@app.route('/user_items')
|
@app.route('/user_items')
|
||||||
@login_required
|
@login_required
|
||||||
def get_items():
|
def get_items():
|
||||||
items = []
|
return get_items_with_level_restriction(list(range(0, 60)))
|
||||||
radical_count = 0
|
|
||||||
for item in json.loads(current_user.radicals):
|
|
||||||
if item['user_specific'] and item['user_specific']['burned']:
|
@app.route('/user_items/<level_range>')
|
||||||
radical_count += 1
|
@login_required
|
||||||
if item['image']:
|
def get_items_with_range(level_range):
|
||||||
items.append({'item_type': 'radical', 'question': item['image'], 'answer': item['meaning']})
|
return get_items_with_level_restriction(parse_range(level_range))
|
||||||
else:
|
|
||||||
items.append({'item_type': 'radical', 'question': item['character'], 'answer': item['meaning']})
|
|
||||||
kanji_count = 0
|
|
||||||
for item in json.loads(current_user.kanji):
|
|
||||||
kanji_count += 1
|
|
||||||
made_answer = ""
|
|
||||||
if item['user_specific'] and item['user_specific']['burned']:
|
|
||||||
if item['onyomi'] and item['kunyomi']:
|
|
||||||
made_answer = item['onyomi'] + ',' + item['kunyomi'].replace('.*', '')
|
|
||||||
elif item['onyomi']:
|
|
||||||
made_answer = item['onyomi']
|
|
||||||
elif item['kunyomi']:
|
|
||||||
made_answer = item['kunyomi'].replace('.*', '')
|
|
||||||
items.append({'item_type': 'kanji', 'question': item['character'], 'answer': made_answer,
|
|
||||||
'answer_meaning': item['meaning']})
|
|
||||||
vocabulary_count = 0
|
|
||||||
for item in json.loads(current_user.vocabulary):
|
|
||||||
if item['user_specific'] and item['user_specific']['burned']:
|
|
||||||
vocabulary_count += 1
|
|
||||||
items.append({'item_type': 'vocabulary', 'question': item['character'], 'answer': item['kana'],
|
|
||||||
'answer_meaning': item['meaning']})
|
|
||||||
return jsonify(radical_count=radical_count, kanji_count=kanji_count, vocabulary_count=vocabulary_count,
|
|
||||||
item_list=items)
|
|
||||||
|
|
||||||
|
|
||||||
@app.route('/refresh', methods=['POST'])
|
@app.route('/refresh', methods=['POST'])
|
||||||
|
Loading…
Reference in New Issue
Block a user