Updated response logic to filter only burned items now that database includes non-burned items.

This commit is contained in:
neviyn 2015-10-11 22:46:07 +01:00
parent 3a5811cafd
commit ff19b0e6b9

View File

@ -134,28 +134,31 @@ def get_items():
items = [] items = []
radical_count = 0 radical_count = 0
for item in json.loads(current_user.radicals): for item in json.loads(current_user.radicals):
radical_count += 1 if item['user_specific'] and item['user_specific']['burned']:
if item['image']: radical_count += 1
items.append({'item_type': 'radical', 'question': item['image'], 'answer': item['meaning']}) if item['image']:
else: items.append({'item_type': 'radical', 'question': item['image'], 'answer': item['meaning']})
items.append({'item_type': 'radical', 'question': item['character'], 'answer': item['meaning']}) else:
items.append({'item_type': 'radical', 'question': item['character'], 'answer': item['meaning']})
kanji_count = 0 kanji_count = 0
for item in json.loads(current_user.kanji): for item in json.loads(current_user.kanji):
kanji_count += 1 kanji_count += 1
made_answer = "" made_answer = ""
if item['onyomi'] and item['kunyomi']: if item['user_specific'] and item['user_specific']['burned']:
made_answer = item['onyomi'] + ',' + item['kunyomi'].replace('.*', '') if item['onyomi'] and item['kunyomi']:
elif item['onyomi']: made_answer = item['onyomi'] + ',' + item['kunyomi'].replace('.*', '')
made_answer = item['onyomi'] elif item['onyomi']:
elif item['kunyomi']: made_answer = item['onyomi']
made_answer = item['kunyomi'].replace('.*', '') elif item['kunyomi']:
items.append({'item_type': 'kanji', 'question': item['character'], 'answer': made_answer, made_answer = item['kunyomi'].replace('.*', '')
'answer_meaning': item['meaning']}) items.append({'item_type': 'kanji', 'question': item['character'], 'answer': made_answer,
'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):
vocabulary_count += 1 if item['user_specific'] and item['user_specific']['burned']:
items.append({'item_type': 'vocabulary', 'question': item['character'], 'answer': item['kana'], vocabulary_count += 1
'answer_meaning': item['meaning']}) 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, return jsonify(radical_count=radical_count, kanji_count=kanji_count, vocabulary_count=vocabulary_count,
item_list=items) item_list=items)