Merge pull request #326 from lovac42/fix_cased_fieldNames

Fix case sensitive field names
This commit is contained in:
Damien Elmes 2019-08-21 17:50:38 +10:00 committed by GitHub
commit 6d46676a76
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

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