1
This commit is contained in:
Alex Yatskov 2016-05-05 18:56:00 -07:00
parent cbdb011664
commit 26d3fa3106

View File

@ -55,7 +55,7 @@ class AnkiConnect:
self.server.advance() self.server.advance()
def prepareNoteParams(self, definition, mode): def prepareNoteArgs(self, definition, mode):
if definition is None: if definition is None:
return None return None
@ -89,40 +89,40 @@ class AnkiConnect:
def handler(self, request): def handler(self, request):
action = request.get('action') action = request.get('action')
data = request.get('data') params = request.get('params')
return self.handlers.get(action, self.apiInvalidRequest)(data) return self.handlers.get(action, self.apiInvalidRequest)(params)
def apiAddNote(self, data): def apiAddNote(self, params):
params = self.prepareNoteParams(data.get('definition'), data.get('mode')) args = self.prepareNoteArgs(params.get('definition'), params.get('mode'))
if params is not None: if args is not None:
return self.anki.addNote(params['deck'], params['model'], params['fields'], params['tags']) return self.anki.addNote(args['deck'], args['model'], args['fields'], args['tags'])
def apiCanAddNote(self, data): def apiCanAddNote(self, params):
params = self.prepareNoteParams(data.get('definition'), data.get('mode')) args = self.prepareNoteArgs(params.get('definition'), params.get('mode'))
if params is not None: if args is not None:
return self.anki.canAddNote(params['deck'], params['model'], params['fields']) return self.anki.canAddNote(args['deck'], args['model'], args['fields'])
def apiCanAddNotes(self, data): def apiCanAddNotes(self, params):
for definition in data: for definition in params:
definition['addable'] = results = {} results = definition['addable'] = definition.get('addable', {})
for mode in ['vocabExp', 'vocabReading', 'kanji']: for mode in ['vocabExp', 'vocabReading', 'kanji']:
params = self.prepareNoteParams(definition, mode) args = self.prepareNoteArgs(definition, mode)
results[mode] = params is not None and self.anki.canAddNote( results[mode] = args is not None and self.anki.canAddNote(
params['deck'], args['deck'],
params['model'], args['model'],
params['fields'] args['fields']
) )
return data return params
def apiGetVersion(self, data): def apiGetVersion(self, params):
return {'version': constants.c['appVersion']} return {'version': constants.c['appVersion']}
def apiInvalidRequest(self, data): def apiInvalidRequest(self, params):
return None return None