This commit is contained in:
Alex Yatskov 2018-03-31 14:40:01 -07:00
parent d3627e3060
commit 0efa203095

View File

@ -117,7 +117,6 @@ def verifyStringList(strings):
return True return True
# #
# AjaxRequest # AjaxRequest
# #
@ -337,7 +336,8 @@ class AnkiNoteParams:
type(self.fields) == dict and verifyStringList(list(self.fields.keys())) and verifyStringList(list(self.fields.values())) and type(self.fields) == dict and verifyStringList(list(self.fields.keys())) and verifyStringList(list(self.fields.values())) and
type(self.tags) == list and verifyStringList(self.tags) type(self.tags) == list and verifyStringList(self.tags)
) )
def __str__(self): def __str__(self):
return 'DeckName: ' + self.deckName + '. ModelName: ' + self.modelName + '. Fields: ' + str(self.fields) + '. Tags: ' + str(self.tags) + '.' return 'DeckName: ' + self.deckName + '. ModelName: ' + self.modelName + '. Fields: ' + str(self.fields) + '. Tags: ' + str(self.tags) + '.'
@ -437,6 +437,7 @@ class AnkiBridge:
elif duplicateOrEmpty == False: elif duplicateOrEmpty == False:
return note return note
def updateNoteFields(self, params): def updateNoteFields(self, params):
collection = self.collection() collection = self.collection()
if collection is None: if collection is None:
@ -450,6 +451,7 @@ class AnkiBridge:
note[name] = value note[name] = value
note.flush() note.flush()
def addTags(self, notes, tags, add=True): def addTags(self, notes, tags, add=True):
self.startEditing() self.startEditing()
self.collection().tags.bulkAdd(notes, tags, add) self.collection().tags.bulkAdd(notes, tags, add)
@ -479,6 +481,7 @@ class AnkiBridge:
return False return False
def isSuspended(self, card): def isSuspended(self, card):
card = self.collection().getCard(card) card = self.collection().getCard(card)
if card.queue == -1: if card.queue == -1:
@ -486,6 +489,7 @@ class AnkiBridge:
else: else:
return False return False
def areSuspended(self, cards): def areSuspended(self, cards):
suspended = [] suspended = []
for card in cards: for card in cards:
@ -725,6 +729,7 @@ class AnkiBridge:
else: else:
return [] return []
def cardsInfo(self,cards): def cardsInfo(self,cards):
result = [] result = []
for cid in cards: for cid in cards:
@ -737,7 +742,7 @@ class AnkiBridge:
order = info['ord'] order = info['ord']
name = info['name'] name = info['name']
fields[name] = {'value': note.fields[order], 'order': order} fields[name] = {'value': note.fields[order], 'order': order}
result.append({ result.append({
'cardId': card.id, 'cardId': card.id,
'fields': fields, 'fields': fields,
@ -747,8 +752,8 @@ class AnkiBridge:
'modelName': model['name'], 'modelName': model['name'],
'deckName': self.deckNameFromId(card.did), 'deckName': self.deckNameFromId(card.did),
'css': model['css'], 'css': model['css'],
'factor': card.factor, 'factor': card.factor,
#This factor is 10 times the ease percentage, #This factor is 10 times the ease percentage,
# so an ease of 310% would be reported as 3100 # so an ease of 310% would be reported as 3100
'interval': card.ivl, 'interval': card.ivl,
'note': card.nid 'note': card.nid
@ -762,6 +767,7 @@ class AnkiBridge:
return result return result
def notesInfo(self,notes): def notesInfo(self,notes):
result = [] result = []
for nid in notes: for nid in notes:
@ -774,7 +780,7 @@ class AnkiBridge:
order = info['ord'] order = info['ord']
name = info['name'] name = info['name']
fields[name] = {'value': note.fields[order], 'order': order} fields[name] = {'value': note.fields[order], 'order': order}
result.append({ result.append({
'noteId': note.id, 'noteId': note.id,
'tags' : note.tags, 'tags' : note.tags,
@ -813,6 +819,7 @@ class AnkiBridge:
return deckId return deckId
def changeDeck(self, cards, deck): def changeDeck(self, cards, deck):
self.startEditing() self.startEditing()
@ -906,6 +913,7 @@ class AnkiBridge:
else: else:
return False return False
def guiShowQuestion(self): def guiShowQuestion(self):
if self.guiReviewActive(): if self.guiReviewActive():
self.reviewer()._showQuestion() self.reviewer()._showQuestion()
@ -959,6 +967,7 @@ class AnkiBridge:
else: else:
return False return False
def guiExitAnki(self): def guiExitAnki(self):
timer = QTimer() timer = QTimer()
def exitAnki(): def exitAnki():
@ -967,9 +976,11 @@ class AnkiBridge:
timer.timeout.connect(exitAnki) timer.timeout.connect(exitAnki)
timer.start(1000) # 1s should be enough to allow the response to be sent. timer.start(1000) # 1s should be enough to allow the response to be sent.
def sync(self): def sync(self):
self.window().onSync() self.window().onSync()
# #
# AnkiConnect # AnkiConnect
# #
@ -1134,10 +1145,12 @@ class AnkiConnect:
return results return results
@webApi() @webApi()
def updateNoteFields(self, note): def updateNoteFields(self, note):
return self.anki.updateNoteFields(note) return self.anki.updateNoteFields(note)
@webApi() @webApi()
def canAddNotes(self, notes): def canAddNotes(self, notes):
results = [] results = []
@ -1230,10 +1243,12 @@ class AnkiConnect:
def getDecks(self, cards): def getDecks(self, cards):
return self.anki.getDecks(cards) return self.anki.getDecks(cards)
@webApi() @webApi()
def createDeck(self, deck): def createDeck(self, deck):
return self.anki.createDeck(deck) return self.anki.createDeck(deck)
@webApi() @webApi()
def changeDeck(self, cards, deck): def changeDeck(self, cards, deck):
return self.anki.changeDeck(cards, deck) return self.anki.changeDeck(cards, deck)
@ -1303,14 +1318,17 @@ class AnkiConnect:
def guiExitAnki(self): def guiExitAnki(self):
return self.anki.guiExitAnki() return self.anki.guiExitAnki()
@webApi() @webApi()
def cardsInfo(self, cards): def cardsInfo(self, cards):
return self.anki.cardsInfo(cards) return self.anki.cardsInfo(cards)
@webApi() @webApi()
def notesInfo(self, notes): def notesInfo(self, notes):
return self.anki.notesInfo(notes) return self.anki.notesInfo(notes)
@webApi() @webApi()
def sync(self): def sync(self):
return self.anki.sync() return self.anki.sync()