mirror of
https://github.com/ankitects/anki.git
synced 2025-09-20 23:12:21 -04:00
fix templates not being properly upgraded
This commit is contained in:
parent
4477e21369
commit
8170b2a2f5
1 changed files with 16 additions and 16 deletions
|
@ -401,11 +401,12 @@ def _migrateFieldsTbl(db):
|
||||||
dconf = anki.models.defaultField
|
dconf = anki.models.defaultField
|
||||||
mods = {}
|
mods = {}
|
||||||
for row in db.all("""
|
for row in db.all("""
|
||||||
select id, modelId, ordinal, name, features, required, "unique",
|
select modelId, name, features, required, "unique",
|
||||||
quizFontFamily, quizFontSize, quizFontColour, editFontSize from fieldModels"""):
|
quizFontFamily, quizFontSize, quizFontColour, editFontSize from fieldModels
|
||||||
|
order by modelId, ordinal"""):
|
||||||
conf = dconf.copy()
|
conf = dconf.copy()
|
||||||
if row[1] not in mods:
|
if row[0] not in mods:
|
||||||
mods[row[1]] = []
|
mods[row[0]] = []
|
||||||
(conf['name'],
|
(conf['name'],
|
||||||
conf['rtl'],
|
conf['rtl'],
|
||||||
conf['req'],
|
conf['req'],
|
||||||
|
@ -413,17 +414,16 @@ quizFontFamily, quizFontSize, quizFontColour, editFontSize from fieldModels"""):
|
||||||
conf['font'],
|
conf['font'],
|
||||||
conf['qsize'],
|
conf['qsize'],
|
||||||
conf['qcol'],
|
conf['qcol'],
|
||||||
conf['esize']) = row[3:]
|
conf['esize']) = row[1:]
|
||||||
# ensure data is good
|
# ensure data is good
|
||||||
conf['rtl'] = not not conf['rtl']
|
conf['rtl'] = not not conf['rtl']
|
||||||
conf['pre'] = True
|
conf['pre'] = True
|
||||||
conf['qcol'] = conf['qcol'] or "#fff"
|
conf['qcol'] = conf['qcol'] or "#fff"
|
||||||
# add to model list with ordinal for sorting
|
mods[row[0]].append(conf)
|
||||||
mods[row[1]].append((row[2], conf))
|
|
||||||
# now we've gathered all the info, save it into the models
|
# now we've gathered all the info, save it into the models
|
||||||
for mid, fms in mods.items():
|
for mid, fms in mods.items():
|
||||||
db.execute("update models set flds = ? where id = ?",
|
db.execute("update models set flds = ? where id = ?",
|
||||||
simplejson.dumps([x[1] for x in sorted(fms)]), mid)
|
simplejson.dumps(fms), mid)
|
||||||
# clean up
|
# clean up
|
||||||
db.execute("drop table fieldModels")
|
db.execute("drop table fieldModels")
|
||||||
return mods
|
return mods
|
||||||
|
@ -433,10 +433,11 @@ def _migrateTemplatesTbl(db, fmods):
|
||||||
dconf = anki.models.defaultTemplate
|
dconf = anki.models.defaultTemplate
|
||||||
mods = {}
|
mods = {}
|
||||||
for row in db.all("""
|
for row in db.all("""
|
||||||
select modelId, ordinal, name, active, qformat, aformat, questionInAnswer,
|
select modelId, name, active, qformat, aformat, questionInAnswer,
|
||||||
questionAlign, lastFontColour, allowEmptyAnswer, typeAnswer from cardModels"""):
|
questionAlign, lastFontColour, allowEmptyAnswer, typeAnswer from cardModels
|
||||||
|
order by modelId, ordinal"""):
|
||||||
conf = dconf.copy()
|
conf = dconf.copy()
|
||||||
if row[1] not in mods:
|
if row[0] not in mods:
|
||||||
mods[row[0]] = []
|
mods[row[0]] = []
|
||||||
(conf['name'],
|
(conf['name'],
|
||||||
conf['actv'],
|
conf['actv'],
|
||||||
|
@ -446,10 +447,10 @@ questionAlign, lastFontColour, allowEmptyAnswer, typeAnswer from cardModels"""):
|
||||||
conf['align'],
|
conf['align'],
|
||||||
conf['bg'],
|
conf['bg'],
|
||||||
conf['emptyAns'],
|
conf['emptyAns'],
|
||||||
conf['typeAns']) = row[2:]
|
conf['typeAns']) = row[1:]
|
||||||
# convert the field name to an ordinal
|
# convert the field name to an ordinal
|
||||||
ordN = None
|
ordN = None
|
||||||
for (ord, fm) in fmods[row[0]]:
|
for (ord, fm) in enumerate(fmods[row[0]]):
|
||||||
if fm['name'] == row[1]:
|
if fm['name'] == row[1]:
|
||||||
ordN = ord
|
ordN = ord
|
||||||
break
|
break
|
||||||
|
@ -467,12 +468,11 @@ questionAlign, lastFontColour, allowEmptyAnswer, typeAnswer from cardModels"""):
|
||||||
"(?i){{cardModel}}", "{{Template}}", conf[type])
|
"(?i){{cardModel}}", "{{Template}}", conf[type])
|
||||||
conf[type] = re.sub(
|
conf[type] = re.sub(
|
||||||
"(?i){{modelTags}}", "{{Model}}", conf[type])
|
"(?i){{modelTags}}", "{{Model}}", conf[type])
|
||||||
# add to model list with ordinal for sorting
|
mods[row[0]].append(conf)
|
||||||
mods[row[0]].append((row[1], conf))
|
|
||||||
# now we've gathered all the info, save it into the models
|
# now we've gathered all the info, save it into the models
|
||||||
for mid, tmpls in mods.items():
|
for mid, tmpls in mods.items():
|
||||||
db.execute("update models set tmpls = ? where id = ?",
|
db.execute("update models set tmpls = ? where id = ?",
|
||||||
simplejson.dumps([x[1] for x in sorted(tmpls)]), mid)
|
simplejson.dumps(tmpls), mid)
|
||||||
# clean up
|
# clean up
|
||||||
db.execute("drop table cardModels")
|
db.execute("drop table cardModels")
|
||||||
return mods
|
return mods
|
||||||
|
|
Loading…
Reference in a new issue