1
This commit is contained in:
Alex Yatskov 2012-12-23 19:13:45 -08:00
parent ea8d926dfa
commit cd58fcfad4

View File

@ -21,8 +21,8 @@ import re
class Anki: class Anki:
def addNote(self, fields, tags=unicode()): def addNote(self, deckName, modelName, fields, tags=unicode()):
note = self.createNote(fields, tags) note = self.createNote(fields, deckName, modelName, tags)
if not note: if not note:
return None return None
@ -36,21 +36,45 @@ class Anki:
return bool(self.createNote(fields)) return bool(self.createNote(fields))
def createNote(self, fields, tags=unicode()): def createNote(self, deckName, modelName, fields, tags=unicode()):
note = self.collection().newNote() deck = self.findDeck(deckName)
if deck is None:
return None
model = self.findModel(modelName)
if model is None:
return None
note = self.collection().newNote()
note.tags = re.split('[;,\s]', tags) note.tags = re.split('[;,\s]', tags)
note.model()['did'] = deck['id']
for name, value in fields.items(): for name, value in fields.items():
note[name] = value note[name] = value
return None if note.dumpOrEmpty() else note return None if note.dumpOrEmpty() else note
def browseNote(self, noteId): def setCurrentModel(self, modelName):
browser = ui.dialogs.get('CardList', self.window()) #m = self.deck.models.byName(ret.name)
browser.dialog.filterEdit.setText('fid:' + str(noteId)) #self.deck.conf['curModel'] = m['id']
browser.updateSearch() #cdeck = self.deck.decks.current()
browser.onnote() #cdeck['mid'] = m['id']
#self.deck.decks.save(cdeck)
#runHook("currentModelChanged")
#self.mw.reset()
pass
def setCurrentDeck(self, deckName):
pass
#def browseNote(self, noteId):
#browser = ui.dialogs.get('CardList', self.window())
#browser.dialog.filterEdit.setText('fid:' + str(noteId))
#browser.updateSearch()
#browser.onnote()
def window(self): def window(self):
@ -82,9 +106,11 @@ class Anki:
def findModel(self, name): def findModel(self, name):
for model in self.models().models.values(): return self.models().byName(name)
if model['name'] == name:
return model
def currentModel(self):
return self.models().current()
def decks(self): def decks(self):
@ -96,7 +122,9 @@ class Anki:
def findDeck(self, name): def findDeck(self, name):
for deck in self.decks().decks.values(): return self.decks().byName(name)
if deck['name'] == name:
return deck
def currentDeck(self):
return self.decks().current()