when renaming a field, support cloze: as well

This commit is contained in:
Damien Elmes 2012-04-22 08:01:17 +09:00
parent 68da292ddb
commit 62b44df78e

View file

@ -264,16 +264,15 @@ select id from cards where nid in (select id from notes where mid = ?)""",
def renameField(self, m, field, newName): def renameField(self, m, field, newName):
self.col.modSchema() self.col.modSchema()
pat = "({{|[:#^/])%s(}})"
for t in m['tmpls']: for t in m['tmpls']:
types = ("{{%s}}", "{{text:%s}}", "{{#%s}}",
"{{^%s}}", "{{/%s}}")
for type in types:
for fmt in ('qfmt', 'afmt'): for fmt in ('qfmt', 'afmt'):
if newName: if newName:
repl = type%newName t[fmt] = re.sub(
pat % field['name'], "\\1%s\\2" % newName, t[fmt])
else: else:
repl = "" t[fmt] = re.sub(
t[fmt] = t[fmt].replace(type%field['name'], repl) pat % field['name'], "", t[fmt])
field['name'] = newName field['name'] = newName
self.save(m) self.save(m)