From a90773689557fe4682d656c23e661e3f9d4186d6 Mon Sep 17 00:00:00 2001 From: Nathan Cannon Date: Tue, 17 Nov 2015 18:58:07 +0000 Subject: [PATCH] Added query element for /user_items to filter item srs state. --- wanikaniburned.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/wanikaniburned.py b/wanikaniburned.py index a9b3df8..415c9ed 100644 --- a/wanikaniburned.py +++ b/wanikaniburned.py @@ -104,11 +104,11 @@ def parse_range(input_range): return result -def get_items_with_level_restriction(level_range): +def get_items_with_level_restriction(level_range, item_state): 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: + if item['user_specific'] and item['user_specific']['srs'] in item_state and item['level'] in level_range: radical_count += 1 if item['image']: items.append({'item_type': 'radical', 'question': item['image'], 'answer': item['meaning']}) @@ -117,7 +117,7 @@ def get_items_with_level_restriction(level_range): kanji_count = 0 for item in json.loads(current_user.kanji): made_answer = "" - if item['user_specific'] and item['user_specific']['burned'] and item['level'] in level_range: + if item['user_specific'] and item['user_specific']['srs'] in item_state and item['level'] in level_range: kanji_count += 1 if item['onyomi'] and item['kunyomi']: made_answer = item['onyomi'] + ',' + item['kunyomi'].replace('.*', '') @@ -129,7 +129,7 @@ def get_items_with_level_restriction(level_range): '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: + if item['user_specific'] and item['user_specific']['srs'] in item_state and item['level'] in level_range: vocabulary_count += 1 items.append({'item_type': 'vocabulary', 'question': item['character'], 'answer': item['kana'], 'answer_meaning': item['meaning']}) @@ -184,7 +184,10 @@ def get_items(): 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) + item_state = ['burned'] + if request.args.get('item_state'): + item_state = request.args.get('item_state').split(',') + return get_items_with_level_restriction(level_range, item_state) @app.route('/refresh', methods=['POST'])