Fix case sensitive field names so that 'apple' and 'Apple' both show up in drop down list when performing a search and replace.

This commit is contained in:
lovac42 2019-08-20 22:28:45 -04:00
parent b0bf0adacf
commit 0007c98e8d

View file

@ -530,28 +530,22 @@ def findReplace(col, nids, src, dst, regex=False, field=None, fold=True):
def fieldNames(col, downcase=True): def fieldNames(col, downcase=True):
fields = set() fields = set()
names = []
for m in col.models.all(): for m in col.models.all():
for f in m['flds']: for f in m['flds']:
if f['name'].lower() not in fields: name=f['name'].lower() if downcase else f['name']
names.append(f['name']) if name not in fields: #slower w/o
fields.add(f['name'].lower()) fields.add(name)
if downcase: return list(fields)
return list(fields)
return names
def fieldNamesForNotes(col, nids): def fieldNamesForNotes(col, nids):
downcasedNames = set() fields = set()
origNames = []
mids = col.db.list("select distinct mid from notes where id in %s" % ids2str(nids)) mids = col.db.list("select distinct mid from notes where id in %s" % ids2str(nids))
for mid in mids: for mid in mids:
model = col.models.get(mid) model = col.models.get(mid)
for field in col.models.fieldNames(model): for name in col.models.fieldNames(model):
if field.lower() not in downcasedNames: if name not in fields: #slower w/o
downcasedNames.add(field.lower()) fields.add(name)
origNames.append(field) return sorted(list(fields), key=lambda x: x.lower())
return sorted(origNames, key=lambda x: x.lower())
# Find duplicates # Find duplicates
########################################################################## ##########################################################################