handle bad field references and tags; don't create empty fields

This commit is contained in:
Damien Elmes 2011-10-30 10:12:24 +09:00
parent e99e7baa3c
commit 3bf0b253f2

View file

@ -431,15 +431,6 @@ order by ordinal""", mid)):
# we've converted this field before # we've converted this field before
new = state['mflds'][all] new = state['mflds'][all]
else: else:
# find a free field name
while 1:
state['fields'] += 1
fld = "Media %d" % state['fields']
if fld not in deck.models.fieldMap(m).keys():
break
# add the new field
f = deck.models.newField(fld)
deck.models.addField(m, f)
# get field name and any prefix/suffix # get field name and any prefix/suffix
m2 = re.match( m2 = re.match(
"([^{]*)\{\{\{?(?:text:)?([^}]+)\}\}\}?(.*)", "([^{]*)\{\{\{?(?:text:)?([^}]+)\}\}\}?(.*)",
@ -449,7 +440,20 @@ order by ordinal""", mid)):
return return
pre, ofld, suf = m2.groups() pre, ofld, suf = m2.groups()
# get index of field name # get index of field name
try:
idx = deck.models.fieldMap(m)[ofld][0] idx = deck.models.fieldMap(m)[ofld][0]
except:
# invalid field or tag reference; don't rewrite
return
# find a free field name
while 1:
state['fields'] += 1
fld = "Media %d" % state['fields']
if fld not in deck.models.fieldMap(m).keys():
break
# add the new field
f = deck.models.newField(fld)
deck.models.addField(m, f)
# loop through facts and write reference into new field # loop through facts and write reference into new field
data = [] data = []
for id, flds in self.deck.db.execute( for id, flds in self.deck.db.execute(