Added query element for /user_items to filter item srs state.

This commit is contained in:
neviyn 2015-11-17 18:58:07 +00:00
parent 231b4231a3
commit a907736895

View File

@ -104,11 +104,11 @@ def parse_range(input_range):
return result return result
def get_items_with_level_restriction(level_range): def get_items_with_level_restriction(level_range, item_state):
items = [] items = []
radical_count = 0 radical_count = 0
for item in json.loads(current_user.radicals): 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 radical_count += 1
if item['image']: if item['image']:
items.append({'item_type': 'radical', 'question': item['image'], 'answer': item['meaning']}) 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 kanji_count = 0
for item in json.loads(current_user.kanji): for item in json.loads(current_user.kanji):
made_answer = "" 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 kanji_count += 1
if item['onyomi'] and item['kunyomi']: if item['onyomi'] and item['kunyomi']:
made_answer = item['onyomi'] + ',' + item['kunyomi'].replace('.*', '') made_answer = item['onyomi'] + ',' + item['kunyomi'].replace('.*', '')
@ -129,7 +129,7 @@ def get_items_with_level_restriction(level_range):
'answer_meaning': item['meaning']}) 'answer_meaning': item['meaning']})
vocabulary_count = 0 vocabulary_count = 0
for item in json.loads(current_user.vocabulary): 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 vocabulary_count += 1
items.append({'item_type': 'vocabulary', 'question': item['character'], 'answer': item['kana'], items.append({'item_type': 'vocabulary', 'question': item['character'], 'answer': item['kana'],
'answer_meaning': item['meaning']}) 'answer_meaning': item['meaning']})
@ -184,7 +184,10 @@ def get_items():
level_range = list(range(0, 61)) level_range = list(range(0, 61))
if request.args.get('level_range'): if request.args.get('level_range'):
level_range = parse_range(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']) @app.route('/refresh', methods=['POST'])