Code for note creation and addition
This commit is contained in:
parent
4859050faf
commit
ea8d926dfa
@ -26,16 +26,8 @@ class Anki:
|
|||||||
if not note:
|
if not note:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
action = lang._('Add')
|
self.collection().addNote(note)
|
||||||
|
self.window().requireReset()
|
||||||
collection = self.collection()
|
|
||||||
collection.setUndoStart(action)
|
|
||||||
collection.addNote(note, False)
|
|
||||||
collection.setUndoEnd(action)
|
|
||||||
collection.rebuildCounts()
|
|
||||||
|
|
||||||
ankiqt.mw.updateTitleBar()
|
|
||||||
ankiqt.mw.statusView.redraw()
|
|
||||||
|
|
||||||
return note.id
|
return note.id
|
||||||
|
|
||||||
@ -45,19 +37,13 @@ class Anki:
|
|||||||
|
|
||||||
|
|
||||||
def createNote(self, fields, tags=unicode()):
|
def createNote(self, fields, tags=unicode()):
|
||||||
collection = self.collection()
|
note = self.collection().newNote()
|
||||||
note = collection.newnote()
|
|
||||||
note.tags = self.cleanupTags(tags)
|
|
||||||
|
|
||||||
try:
|
note.tags = re.split('[;,\s]', tags)
|
||||||
for field in note.fields:
|
for name, value in fields.items():
|
||||||
field.value = fields.get(field.getName()) or unicode()
|
note[name] = value
|
||||||
if not note.fieldValid(field) or not note.fieldUnique(field, collection.s):
|
|
||||||
return None
|
|
||||||
except KeyError:
|
|
||||||
return None
|
|
||||||
|
|
||||||
return note
|
return None if note.dumpOrEmpty() else note
|
||||||
|
|
||||||
|
|
||||||
def browseNote(self, noteId):
|
def browseNote(self, noteId):
|
||||||
@ -67,10 +53,6 @@ class Anki:
|
|||||||
browser.onnote()
|
browser.onnote()
|
||||||
|
|
||||||
|
|
||||||
def cleanupTags(self, tags):
|
|
||||||
return re.sub('[;,]', unicode(), tags).strip()
|
|
||||||
|
|
||||||
|
|
||||||
def window(self):
|
def window(self):
|
||||||
return aqt.mw
|
return aqt.mw
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user