本文整理汇总了Python中anki.models.ModelManager.save方法的典型用法代码示例。如果您正苦于以下问题:Python ModelManager.save方法的具体用法?Python ModelManager.save怎么用?Python ModelManager.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类anki.models.ModelManager
的用法示例。
在下文中一共展示了ModelManager.save方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add
# 需要导入模块: from anki.models import ModelManager [as 别名]
# 或者: from anki.models.ModelManager import save [as 别名]
def add(self, front, back, deck_name, model_name):
default_deck = self.collection.decks.allNames()[0]
default_model = self.collection.models.allNames()[0]
deck_name = unicode(deck_name or default_deck, sys.getfilesystemencoding())
model_name = unicode(model_name or default_model, sys.getfilesystemencoding())
model = self.collection.models.byName(model_name)
if not model:
mm = ModelManager(self.collection)
model = mm.new(model_name)
mm.save(model)
model['did'] = did = self.collection.decks.id(deck_name)
self.collection.models.save()
note = self.collection.newNote()
note['Front']= unicode(front or "", sys.getfilesystemencoding())
note['Back']= unicode(back or "", sys.getfilesystemencoding())
note.model()['did']= did
self.collection.addNote(note)
self.collection.save()
self.collection.genCards(self.collection.models.nids(model))
示例2: _Collection
# 需要导入模块: from anki.models import ModelManager [as 别名]
# 或者: from anki.models.ModelManager import save [as 别名]
class _Collection(object):
def __init__(self, db, server=False, log=False):
self._debugLog = log
self.db = db
self.path = db._path
self._openLog()
self.log(self.path, anki.version)
self.server = server
self._lastSave = time.time()
self.clearUndo()
self.models = ModelManager(self)
self.decks = DeckManager(self)
self.load()
if not self.crt:
d = datetime.datetime.today()
d -= datetime.timedelta(hours=4)
d = datetime.datetime(d.year, d.month, d.day)
d += datetime.timedelta(hours=4)
self.crt = int(time.mktime(d.timetuple()))
self.sched = Scheduler(self)
if not self.conf.get("newBury", False):
self.conf['newBury'] = True
self.setMod()
def name(self):
n = os.path.splitext(os.path.basename(self.path))[0]
return n
# DB-related
##########################################################################
def load(self):
(self.crt,
self.mod,
self.scm,
self.dty, # no longer used
self._usn,
self.ls,
self.conf,
models,
decks,
dconf,
tags) = self.db.first("""
select crt, mod, scm, dty, usn, ls,
conf, models, decks, dconf, tags from col""")
self.conf = json.loads(self.conf)
#self.models.load(models)
self.decks.load(decks, dconf)
def setMod(self):
"""Mark DB modified.
DB operations and the deck/tag/model managers do this automatically, so this
is only necessary if you modify properties of this object or the conf dict."""
self.db.mod = True
def flush(self, mod=None):
"Flush state to DB, updating mod time."
self.mod = intTime(1000) if mod is None else mod
self.db.execute(
"""update col set
crt=?, mod=?, scm=?, dty=?, usn=?, ls=?, conf=?""",
self.crt, self.mod, self.scm, self.dty,
self._usn, self.ls, json.dumps(self.conf))
def save(self, name=None, mod=None):
"Flush, commit DB, and take out another write lock."
# let the managers conditionally flush
self.models.flush()
self.decks.flush()
self.tags.flush()
# and flush deck + bump mod if db has been changed
if self.db.mod:
self.flush(mod=mod)
self.db.commit()
self.lock()
self.db.mod = False
self._markOp(name)
self._lastSave = time.time()
def autosave(self):
"Save if 5 minutes has passed since last save."
if time.time() - self._lastSave > 300:
self.save()
def lock(self):
# make sure we don't accidentally bump mod time
mod = self.db.mod
self.db.execute("update col set mod=mod")
self.db.mod = mod
def close(self, save=True):
"Disconnect from DB."
if self.db:
if save:
self.save()
else:
self.rollback()
if not self.server:
#.........这里部分代码省略.........