From ea8d926dfabc2289b7cfb36fcd02b7f77aab34f1 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sun, 23 Dec 2012 18:54:05 -0800 Subject: [PATCH] Code for note creation and addition --- yomi_base/anki_host.py | 32 +++++++------------------------- 1 file changed, 7 insertions(+), 25 deletions(-) diff --git a/yomi_base/anki_host.py b/yomi_base/anki_host.py index 287ba35..ae9018d 100644 --- a/yomi_base/anki_host.py +++ b/yomi_base/anki_host.py @@ -26,16 +26,8 @@ class Anki: if not note: return None - action = lang._('Add') - - collection = self.collection() - collection.setUndoStart(action) - collection.addNote(note, False) - collection.setUndoEnd(action) - collection.rebuildCounts() - - ankiqt.mw.updateTitleBar() - ankiqt.mw.statusView.redraw() + self.collection().addNote(note) + self.window().requireReset() return note.id @@ -45,19 +37,13 @@ class Anki: def createNote(self, fields, tags=unicode()): - collection = self.collection() - note = collection.newnote() - note.tags = self.cleanupTags(tags) + note = self.collection().newNote() - try: - for field in note.fields: - field.value = fields.get(field.getName()) or unicode() - if not note.fieldValid(field) or not note.fieldUnique(field, collection.s): - return None - except KeyError: - return None + note.tags = re.split('[;,\s]', tags) + for name, value in fields.items(): + note[name] = value - return note + return None if note.dumpOrEmpty() else note def browseNote(self, noteId): @@ -67,10 +53,6 @@ class Anki: browser.onnote() - def cleanupTags(self, tags): - return re.sub('[;,]', unicode(), tags).strip() - - def window(self): return aqt.mw