Use single quotes throughout the code, remove braces around conditions and remove json.dumps where not needed

This commit is contained in:
Charles Henry 2017-06-16 13:58:49 +01:00
parent 3f5dbe904b
commit 5ec3df733e

View File

@ -435,59 +435,59 @@ class AnkiBridge:
def getNextCard(self):
if (self.window().reviewer.card is None) or (self.window().state != "review"):
if self.window().reviewer.card is None or self.window().state != 'review':
self.window().moveToState('review')
card = self.window().reviewer.card
nextCard = {}
nextCard['id'] = card.id
nextCard['question'] = card._getQA()['q']
nextCard['answer'] = card._getQA()['a']
nextCard['answerButtons'] = self.window().reviewer._answerButtonList()
nextCard['model_name'] = card.note(reload)._model['name']
nextCard['ord'] = card.ord
nextCard['fields'] = json.dumps(card.note(reload).fields)
nextCard['_fmap'] = card.note(reload)._fmap
nextCard['success'] = True
return json.dumps(nextCard)
return {
'success': True,
'id': card.id,
'question': card._getQA()['q'],
'answer': card._getQA()['a'],
'answerButtons': self.window().reviewer._answerButtonList(),
'modelName': card.note(reload)._model['name'],
'ord': card.ord,
'fields': card.note(reload).fields,
'fieldMap': card.note(reload)._fmap
}
def showQuestion(self):
if (self.window().reviewer.card is None) or (self.window().state != "review"):
if self.window().reviewer.card is None or self.window().state != 'review':
self.window().moveToState('review')
self.window().reviewer._showQuestion()
return json.dumps({'success': True})
return {'success': True}
def showAnswer(self):
if self.window().reviewer.mw.state != "review":
return json.dumps({'success': False, 'message': 'Window state is not review.'})
if self.window().reviewer.mw.state != 'review':
return {'success': False, 'message': 'Window state is not review.'}
else:
self.window().reviewer._showAnswer()
return json.dumps({'success': True})
return {'success': True}
def answerCard(self, id, ease):
if self.window().reviewer.mw.state != "review":
return json.dumps({'success': False, 'message': 'Window state is not review.'})
elif self.window().reviewer.state != "answer":
return json.dumps({'success': False, 'message': 'Reviewer state is not answer.'})
if self.window().reviewer.mw.state != 'review':
return {'success': False, 'message': 'Window state is not review.'}
elif self.window().reviewer.state != 'answer':
return {'success': False, 'message': 'Reviewer state is not answer.'}
elif self.window().reviewer.card.id != id:
return json.dumps({'success': False, 'message': 'Given card does not match.'})
return {'success': False, 'message': 'Given card does not match.'}
elif self.window().col.sched.answerButtons(self.window().reviewer.card) < ease:
return json.dumps({'success': False, 'message': 'Invalid ease provided.'})
return {'success': False, 'message': 'Invalid ease provided.'}
else:
self.window().reviewer._answerCard(ease)
return json.dumps({'success': True})
return {'success': True}
def checkState(self):
stateInfo = {}
stateInfo['success'] = True
stateInfo['window_state'] = self.window().state
stateInfo['reviewer_state'] = self.window().reviewer.state
return json.dumps(stateInfo)
return {
'success': True,
'window_state': self.window().state,
'reviewer_state': self.window().reviewer.state
}
#