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 = []
radical_count = 0
for item in json.loads(current_user.radicals):
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']})
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['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']})
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):
vocabulary_count += 1
items.append({'item_type': 'vocabulary', 'question': item['character'], 'answer': item['kana'],
'answer_meaning': item['meaning']})
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)