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) ->
|
||||
e.preventDefault();
|
||||
answers = $('#answer').text().split(/[,\.]/g);
|
||||
answers = $.map(answers, (x) -> )
|
||||
input_answer = document.getElementById('kana').value;
|
||||
if($("#kana").hasClass("correct"))
|
||||
refreshQuestion();
|
||||
|
@ -67,10 +67,8 @@
|
||||
});
|
||||
|
||||
$("#submit-answer").click(function(e) {
|
||||
var answers, input_answer;
|
||||
var input_answer;
|
||||
e.preventDefault();
|
||||
answers = $('#answer').text().split(/[,\.]/g);
|
||||
answers = $.map(answers, function(x) {});
|
||||
input_answer = document.getElementById('kana').value;
|
||||
if ($("#kana").hasClass("correct")) {
|
||||
return refreshQuestion();
|
||||
|
@ -90,6 +90,52 @@ class User(db.Model):
|
||||
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
|
||||
def load_user(api_key):
|
||||
return User.query.get(str(api_key))
|
||||
@ -131,36 +177,13 @@ def show_quiz():
|
||||
@app.route('/user_items')
|
||||
@login_required
|
||||
def get_items():
|
||||
items = []
|
||||
radical_count = 0
|
||||
for item in json.loads(current_user.radicals):
|
||||
if item['user_specific'] and item['user_specific']['burned']:
|
||||
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']:
|
||||
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)
|
||||
return get_items_with_level_restriction(list(range(0, 60)))
|
||||
|
||||
|
||||
@app.route('/user_items/<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'])
|
||||
|
Loading…
Reference in New Issue
Block a user