mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
Merge pull request #345 from Arthur-Milchior/noFullSyncWhenEditingNewModel
No full sync when editing new model
This commit is contained in:
commit
0ffb308004
1 changed files with 15 additions and 12 deletions
|
@ -150,11 +150,12 @@ class ModelManager:
|
||||||
m['tmpls'] = []
|
m['tmpls'] = []
|
||||||
m['tags'] = []
|
m['tags'] = []
|
||||||
m['id'] = None
|
m['id'] = None
|
||||||
|
m['usn'] = self.col.usn()
|
||||||
return m
|
return m
|
||||||
|
|
||||||
def rem(self, m):
|
def rem(self, m):
|
||||||
"Delete model, and all its cards/notes."
|
"Delete model, and all its cards/notes."
|
||||||
self.col.modSchema(check=True)
|
self._modSchemaIfRequired(m)
|
||||||
current = self.current()['id'] == m['id']
|
current = self.current()['id'] == m['id']
|
||||||
# delete notes/cards
|
# delete notes/cards
|
||||||
self.col.remCards(self.col.db.list("""
|
self.col.remCards(self.col.db.list("""
|
||||||
|
@ -225,6 +226,7 @@ and notes.mid = ? and cards.ord = ?""", m['id'], ord)
|
||||||
m2 = copy.deepcopy(m)
|
m2 = copy.deepcopy(m)
|
||||||
m2['name'] = _("%s copy") % m2['name']
|
m2['name'] = _("%s copy") % m2['name']
|
||||||
self.add(m2)
|
self.add(m2)
|
||||||
|
m['usn'] = self.col.usn()
|
||||||
return m2
|
return m2
|
||||||
|
|
||||||
# Fields
|
# Fields
|
||||||
|
@ -247,15 +249,13 @@ and notes.mid = ? and cards.ord = ?""", m['id'], ord)
|
||||||
|
|
||||||
def setSortIdx(self, m, idx):
|
def setSortIdx(self, m, idx):
|
||||||
assert 0 <= idx < len(m['flds'])
|
assert 0 <= idx < len(m['flds'])
|
||||||
self.col.modSchema(check=True)
|
self._modSchemaIfRequired(m)
|
||||||
m['sortf'] = idx
|
m['sortf'] = idx
|
||||||
self.col.updateFieldCache(self.nids(m))
|
self.col.updateFieldCache(self.nids(m))
|
||||||
self.save(m)
|
self.save(m)
|
||||||
|
|
||||||
def addField(self, m, field):
|
def addField(self, m, field):
|
||||||
# only mod schema if model isn't new
|
self._modSchemaIfRequired(m)
|
||||||
if m['id']:
|
|
||||||
self.col.modSchema(check=True)
|
|
||||||
m['flds'].append(field)
|
m['flds'].append(field)
|
||||||
self._updateFieldOrds(m)
|
self._updateFieldOrds(m)
|
||||||
self.save(m)
|
self.save(m)
|
||||||
|
@ -265,7 +265,7 @@ and notes.mid = ? and cards.ord = ?""", m['id'], ord)
|
||||||
self._transformFields(m, add)
|
self._transformFields(m, add)
|
||||||
|
|
||||||
def remField(self, m, field):
|
def remField(self, m, field):
|
||||||
self.col.modSchema(check=True)
|
self._modSchemaIfRequired(m)
|
||||||
# save old sort field
|
# save old sort field
|
||||||
sortFldName = m['flds'][m['sortf']]['name']
|
sortFldName = m['flds'][m['sortf']]['name']
|
||||||
idx = m['flds'].index(field)
|
idx = m['flds'].index(field)
|
||||||
|
@ -288,7 +288,7 @@ and notes.mid = ? and cards.ord = ?""", m['id'], ord)
|
||||||
self.renameField(m, field, None)
|
self.renameField(m, field, None)
|
||||||
|
|
||||||
def moveField(self, m, field, idx):
|
def moveField(self, m, field, idx):
|
||||||
self.col.modSchema(check=True)
|
self._modSchemaIfRequired(m)
|
||||||
oldidx = m['flds'].index(field)
|
oldidx = m['flds'].index(field)
|
||||||
if oldidx == idx:
|
if oldidx == idx:
|
||||||
return
|
return
|
||||||
|
@ -309,7 +309,7 @@ and notes.mid = ? and cards.ord = ?""", m['id'], ord)
|
||||||
self._transformFields(m, move)
|
self._transformFields(m, move)
|
||||||
|
|
||||||
def renameField(self, m, field, newName):
|
def renameField(self, m, field, newName):
|
||||||
self.col.modSchema(check=True)
|
self._modSchemaIfRequired(m)
|
||||||
pat = r'{{([^{}]*)([:#^/]|[^:#/^}][^:}]*?:|)%s}}'
|
pat = r'{{([^{}]*)([:#^/]|[^:#/^}][^:}]*?:|)%s}}'
|
||||||
def wrap(txt):
|
def wrap(txt):
|
||||||
def repl(match):
|
def repl(match):
|
||||||
|
@ -352,8 +352,7 @@ and notes.mid = ? and cards.ord = ?""", m['id'], ord)
|
||||||
|
|
||||||
def addTemplate(self, m, template):
|
def addTemplate(self, m, template):
|
||||||
"Note: should col.genCards() afterwards."
|
"Note: should col.genCards() afterwards."
|
||||||
if m['id']:
|
self._modSchemaIfRequired(m)
|
||||||
self.col.modSchema(check=True)
|
|
||||||
m['tmpls'].append(template)
|
m['tmpls'].append(template)
|
||||||
self._updateTemplOrds(m)
|
self._updateTemplOrds(m)
|
||||||
self.save(m)
|
self.save(m)
|
||||||
|
@ -376,7 +375,7 @@ having count() < 2
|
||||||
limit 1""" % ids2str(cids)):
|
limit 1""" % ids2str(cids)):
|
||||||
return False
|
return False
|
||||||
# ok to proceed; remove cards
|
# ok to proceed; remove cards
|
||||||
self.col.modSchema(check=True)
|
self._modSchemaIfRequired(m)
|
||||||
self.col.remCards(cids)
|
self.col.remCards(cids)
|
||||||
# shift ordinals
|
# shift ordinals
|
||||||
self.col.db.execute("""
|
self.col.db.execute("""
|
||||||
|
@ -420,7 +419,7 @@ select id from notes where mid = ?)""" % " ".join(map),
|
||||||
# - newModel should be self if model is not changing
|
# - newModel should be self if model is not changing
|
||||||
|
|
||||||
def change(self, m, nids, newModel, fmap, cmap):
|
def change(self, m, nids, newModel, fmap, cmap):
|
||||||
self.col.modSchema(check=True)
|
self._modSchemaIfRequired(m)
|
||||||
assert newModel['id'] == m['id'] or (fmap and cmap)
|
assert newModel['id'] == m['id'] or (fmap and cmap)
|
||||||
if fmap:
|
if fmap:
|
||||||
self._changeNotes(nids, newModel, fmap)
|
self._changeNotes(nids, newModel, fmap)
|
||||||
|
@ -474,6 +473,10 @@ select id from notes where mid = ?)""" % " ".join(map),
|
||||||
d)
|
d)
|
||||||
self.col.remCards(deleted)
|
self.col.remCards(deleted)
|
||||||
|
|
||||||
|
def _modSchemaIfRequired(self, m):
|
||||||
|
if m['id'] and m["usn"] != -1:
|
||||||
|
self.col.modSchema(check=True)
|
||||||
|
|
||||||
# Schema hash
|
# Schema hash
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue