From da837b2d47d321a0fed4d8cfc35b021750e6b45d Mon Sep 17 00:00:00 2001 From: Albert Date: Sun, 5 Apr 2020 01:28:37 +0800 Subject: [PATCH] Complete 975c069 fixes --- plugin/__init__.py | 19 ++++--------------- plugin/util.py | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/plugin/__init__.py b/plugin/__init__.py index 107188d..77dd3cd 100644 --- a/plugin/__init__.py +++ b/plugin/__init__.py @@ -819,22 +819,12 @@ class AnkiConnect: name = info['name'] fields[name] = {'value': note.fields[order], 'order': order} - if getattr(card, 'question', None) is None: - question = card._getQA()['q'] - else: - question = card.question(), - - if getattr(card, 'answer', None) is None: - answer = card._getQA()['a'] - else: - answer = card.answer() - result.append({ 'cardId': card.id, 'fields': fields, 'fieldOrder': card.ord, - 'question': question, - 'answer': answer, + 'question': util.getQuestion(card), + 'answer': util.getAnswer(card), 'modelName': model['name'], 'deckName': self.deckNameFromId(card.did), 'css': model['css'], @@ -1081,15 +1071,14 @@ class AnkiConnect: order = info['ord'] name = info['name'] fields[name] = {'value': note.fields[order], 'order': order} - if card is not None: buttonList = reviewer._answerButtonList() return { 'cardId': card.id, 'fields': fields, 'fieldOrder': card.ord, - 'question': card.question(), - 'answer': card.answer(), + 'question': util.getQuestion(card), + 'answer': util.getAnswer(card), 'buttons': [b[0] for b in buttonList], 'nextReviews': [reviewer.mw.col.sched.nextIvlStr(reviewer.card, b[0], True) for b in buttonList], 'modelName': model['name'], diff --git a/plugin/util.py b/plugin/util.py index 278271b..a39e206 100644 --- a/plugin/util.py +++ b/plugin/util.py @@ -44,6 +44,22 @@ def api(*versions): return decorator +def getQuestion(card): + if getattr(card, 'question', None) is None: + question = card._getQA()['q'] + else: + question = card.question(), + return question + + +def getAnswer(card): + if getattr(card, 'answer', None) is None: + answer = card._getQA()['a'] + else: + answer = card.answer() + return answer + + def setting(key): defaults = { 'apiKey': None,