WIP
This commit is contained in:
parent
718287360e
commit
8990fbf671
@ -25,6 +25,7 @@ import reader_util
|
|||||||
|
|
||||||
class AnkiConnect:
|
class AnkiConnect:
|
||||||
def __init__(self, anki, preferences, interval=50):
|
def __init__(self, anki, preferences, interval=50):
|
||||||
|
self.anki = anki
|
||||||
self.preferences = preferences
|
self.preferences = preferences
|
||||||
self.server = None
|
self.server = None
|
||||||
|
|
||||||
@ -74,15 +75,14 @@ class AnkiConnect:
|
|||||||
if profile is None:
|
if profile is None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
fields = reader_util.formatFields(
|
markup = markupFunc(definition)
|
||||||
profile['fields'],
|
if markup is None:
|
||||||
markupFunc(definition)
|
return None
|
||||||
)
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'deck': profile['deck'],
|
'deck': profile['deck'],
|
||||||
'model': profile['model'],
|
'model': profile['model'],
|
||||||
'fields': fields,
|
'fields': reader_util.formatFields(profile['fields'], markup),
|
||||||
'tags': self.preferences['tags']
|
'tags': self.preferences['tags']
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,7 +91,7 @@ class AnkiConnect:
|
|||||||
action = request.get('action')
|
action = request.get('action')
|
||||||
data = request.get('data')
|
data = request.get('data')
|
||||||
|
|
||||||
self.handlers.get(action, self.apiInvalidRequest)(data)
|
return self.handlers.get(action, self.apiInvalidRequest)(data)
|
||||||
|
|
||||||
|
|
||||||
def apiAddNote(self, data):
|
def apiAddNote(self, data):
|
||||||
@ -107,10 +107,8 @@ class AnkiConnect:
|
|||||||
|
|
||||||
|
|
||||||
def apiCanAddNotes(self, data):
|
def apiCanAddNotes(self, data):
|
||||||
definitions = data.get('definitions', [])
|
for definition in data:
|
||||||
|
definition['addable'] = results = {}
|
||||||
for definition in definitions:
|
|
||||||
definitions['anki'] = results = {}
|
|
||||||
for mode in ['vocabExp', 'vocabReading', 'kanji']:
|
for mode in ['vocabExp', 'vocabReading', 'kanji']:
|
||||||
params = self.prepareNoteParams(definition, mode)
|
params = self.prepareNoteParams(definition, mode)
|
||||||
results[mode] = params is not None and self.anki.canAddNote(
|
results[mode] = params is not None and self.anki.canAddNote(
|
||||||
@ -119,7 +117,7 @@ class AnkiConnect:
|
|||||||
params['fields']
|
params['fields']
|
||||||
)
|
)
|
||||||
|
|
||||||
return definitions
|
return data
|
||||||
|
|
||||||
|
|
||||||
def apiGetVersion(self, data):
|
def apiGetVersion(self, data):
|
||||||
|
Loading…
Reference in New Issue
Block a user