make the format upgrading smarter

This commit is contained in:
Damien Elmes 2011-01-22 07:36:05 +09:00
parent c1d15b8a9e
commit e042ef5e62

View file

@ -4322,20 +4322,27 @@ this message. (ERR-0101)""") % {
deck.s.statement("update fieldModels set editFontFamily = 1"); deck.s.statement("update fieldModels set editFontFamily = 1");
deck.version = 54 deck.version = 54
deck.s.commit() deck.s.commit()
if deck.version < 55:
# set a default font for unset fonts
deck.s.statement("""
update fieldModels set quizFontFamily = 'Arial' where not quizFontFamily
or quizFontFamily is null""")
deck.version = 55
deck.s.commit()
if deck.version < 57: if deck.version < 57:
deck.version = 57 deck.version = 57
deck.s.commit() deck.s.commit()
if deck.version < 61: if deck.version < 61:
# do our best to upgrade templates to the new style
txt = '''\ txt = '''\
<span style="font-family: %s; font-size: %spx; color: %s;">%s</span>''' <span style="font-family: %s; font-size: %spx; color: %s; white-space: pre-wrap;">%s</span>'''
for m in deck.models: for m in deck.models:
unstyled = []
for fm in m.fieldModels:
# find which fields had explicit formatting
if fm.quizFontFamily or fm.quizFontSize or fm.quizFontColour:
pass
else:
unstyled.append(fm.name)
# fill out missing info
fm.quizFontFamily = fm.quizFontFamily or u"Arial"
fm.quizFontSize = fm.quizFontSize or 20
fm.quizFontColour = fm.quizFontColour or "#000000"
fm.editFontSize = fm.editFontSize or 20
unstyled = set(unstyled)
for cm in m.cardModels: for cm in m.cardModels:
# embed the old font information into card templates # embed the old font information into card templates
cm.qformat = txt % ( cm.qformat = txt % (
@ -4348,9 +4355,10 @@ or quizFontFamily is null""")
cm.answerFontSize, cm.answerFontSize,
cm.answerFontColour, cm.answerFontColour,
cm.aformat) cm.aformat)
# fix newlines # escape fields that had no previous styling
cm.qformat = cm.qformat.replace("\n", "<br>\n") for un in unstyled:
cm.aformat = cm.aformat.replace("\n", "<br>\n") cm.qformat = cm.qformat.replace("%("+un+")s", "{{{%s}}}"%un)
cm.aformat = cm.aformat.replace("%("+un+")s", "{{{%s}}}"%un)
# rebuild q/a for the above & because latex has changed # rebuild q/a for the above & because latex has changed
for m in deck.models: for m in deck.models:
deck.updateCardsFromModel(m, dirty=False) deck.updateCardsFromModel(m, dirty=False)
@ -4369,16 +4377,6 @@ or quizFontFamily is null""")
deck.s.execute("vacuum") deck.s.execute("vacuum")
deck.version = 62 deck.version = 62
deck.s.commit() deck.s.commit()
if deck.version < 63:
# set a default font for unset font sizes
deck.s.statement("""
update fieldModels set quizFontSize = 20 where quizFontSize = ''
or quizFontSize is null""")
deck.s.statement("""
update fieldModels set editFontSize = 20 where editFontSize = ''
or editFontSize is null""")
deck.version = 63
deck.s.commit()
if deck.version < 64: if deck.version < 64:
# remove old static indices, as all clients should be libanki1.2+ # remove old static indices, as all clients should be libanki1.2+
for d in ("ix_cards_duePriority", for d in ("ix_cards_duePriority",