diff --git a/anki/collection.py b/anki/collection.py index fb39e6339..e688c59b8 100644 --- a/anki/collection.py +++ b/anki/collection.py @@ -785,7 +785,7 @@ select id from notes where mid not in """ + ids2str(self.models.ids())) if t['did'] == "None": t['did'] = None problems.append(_("Fixed AnkiDroid deck override bug.")) - self.models.save(m) + self.models.save(m, updateReqs=False) if m['type'] == MODEL_STD: # model with missing req specification if 'req' not in m: diff --git a/anki/importing/pauker.py b/anki/importing/pauker.py index 055c1bfe7..d13e4cade 100644 --- a/anki/importing/pauker.py +++ b/anki/importing/pauker.py @@ -18,7 +18,7 @@ class PaukerImporter(NoteImporter): def run(self): model = addForwardReverse(self.col) model['name'] = "Pauker" - self.col.models.save(model) + self.col.models.save(model, updateReqs=False) self.col.models.setCurrent(model) self.model = model self.initMapping() diff --git a/anki/models.py b/anki/models.py index 8027c5e60..413e427cd 100644 --- a/anki/models.py +++ b/anki/models.py @@ -85,12 +85,13 @@ class ModelManager: self.changed = False self.models = json.loads(json_) - def save(self, m=None, templates=False): + def save(self, m=None, templates=False, updateReqs=True): "Mark M modified if provided, and schedule registry flush." if m and m['id']: m['mod'] = intTime() m['usn'] = self.col.usn() - self._updateRequired(m) + if updateReqs: + self._updateRequired(m) if templates: self._syncTemplates(m) self.changed = True @@ -254,7 +255,7 @@ and notes.mid = ? and cards.ord = ?""", m['id'], ord) self.col.modSchema(check=True) m['sortf'] = idx self.col.updateFieldCache(self.nids(m)) - self.save(m) + self.save(m, updateReqs=False) def addField(self, m, field): # only mod schema if model isn't new @@ -304,7 +305,7 @@ and notes.mid = ? and cards.ord = ?""", m['id'], ord) # restore sort field m['sortf'] = m['flds'].index(sortf) self._updateFieldOrds(m) - self.save(m) + self.save(m, updateReqs=False) def move(fields, oldidx=oldidx): val = fields[oldidx] del fields[oldidx] @@ -409,7 +410,7 @@ update cards set ord = ord - 1, usn = ?, mod = ? for t in m['tmpls']: map.append("when ord = %d then %d" % (oldidxs[id(t)], t['ord'])) # apply - self.save(m) + self.save(m, updateReqs=False) self.col.db.execute(""" update cards set ord = (case %s end),usn=?,mod=? where nid in ( select id from notes where mid = ?)""" % " ".join(map), diff --git a/aqt/editor.py b/aqt/editor.py index c0c3f2041..916f3ad92 100644 --- a/aqt/editor.py +++ b/aqt/editor.py @@ -456,7 +456,7 @@ class Editor: # save tags to model m = self.note.model() m['tags'] = self.note.tags - self.mw.col.models.save(m) + self.mw.col.models.save(m, updateReqs=False) def hideCompleters(self): self.tags.hideCompleter() diff --git a/aqt/importing.py b/aqt/importing.py index bfe2b014e..6d47138fd 100644 --- a/aqt/importing.py +++ b/aqt/importing.py @@ -10,6 +10,7 @@ import json import unicodedata import shutil +from aqt import AnkiQt from aqt.qt import * import anki.importing as importing from aqt.utils import getOnlyText, getFile, showText, showWarning, openHelp, \ @@ -21,7 +22,7 @@ import aqt.deckchooser from anki.lang import ngettext, _ class ChangeMap(QDialog): - def __init__(self, mw, model, current): + def __init__(self, mw: AnkiQt, model, current): QDialog.__init__(self, mw, Qt.Window) self.mw = mw self.model = model @@ -64,7 +65,7 @@ class ChangeMap(QDialog): class ImportDialog(QDialog): - def __init__(self, mw, importer): + def __init__(self, mw: AnkiQt, importer): QDialog.__init__(self, mw, Qt.Window) self.mw = mw self.importer = importer @@ -159,7 +160,7 @@ you can enter it here. Use \\t to represent tab."""), did = self.deck.selectedId() if did != self.importer.model['did']: self.importer.model['did'] = did - self.mw.col.models.save(self.importer.model) + self.mw.col.models.save(self.importer.model, updateReqs=False) self.mw.col.decks.select(did) self.mw.progress.start(immediate=True) self.mw.checkpoint(_("Import")) diff --git a/aqt/models.py b/aqt/models.py index 0ccfe0486..8aba5aaf3 100644 --- a/aqt/models.py +++ b/aqt/models.py @@ -1,6 +1,6 @@ # Copyright: Ankitects Pty Ltd and contributors # License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html - +from aqt import AnkiQt from aqt.qt import * from operator import itemgetter from aqt.utils import showInfo, askUser, getText, maybeHideClose, openHelp @@ -11,12 +11,13 @@ import collections from anki.lang import _, ngettext class Models(QDialog): - def __init__(self, mw, parent=None, fromMain=False): + def __init__(self, mw: AnkiQt, parent=None, fromMain=False): self.mw = mw self.parent = parent or mw self.fromMain = fromMain QDialog.__init__(self, self.parent, Qt.Window) self.col = mw.col + assert(self.col) self.mm = self.col.models self.mw.checkpoint(_("Note Types")) self.form = aqt.forms.models.Ui_Dialog() @@ -56,7 +57,7 @@ class Models(QDialog): txt = getText(_("New name:"), default=self.model['name']) if txt[1] and txt[0]: self.model['name'] = txt[0] - self.mm.save(self.model) + self.mm.save(self.model, updateReqs=False) self.updateModelsList() def updateModelsList(self): @@ -121,7 +122,7 @@ class Models(QDialog): self.model['latexPost'] = str(frm.latexFooter.toPlainText()) def saveModel(self): - self.mm.save(self.model) + self.mm.save(self.model, updateReqs=False) def _tmpNote(self): self.mm.setCurrent(self.model)