mirror of
https://github.com/ankitects/anki.git
synced 2025-09-20 15:02:21 -04:00
make fieldNames() available for gui code too
This commit is contained in:
parent
d51cd5a433
commit
bee14e1a0b
1 changed files with 16 additions and 7 deletions
23
anki/find.py
23
anki/find.py
|
@ -14,6 +14,21 @@ SEARCH_FIELD = 5
|
||||||
SEARCH_MODEL = 6
|
SEARCH_MODEL = 6
|
||||||
SEARCH_GROUP = 7
|
SEARCH_GROUP = 7
|
||||||
|
|
||||||
|
# Tools
|
||||||
|
##########################################################################
|
||||||
|
|
||||||
|
def fieldNames(deck, downcase=True):
|
||||||
|
fields = set()
|
||||||
|
names = []
|
||||||
|
for m in deck.models().values():
|
||||||
|
for f in m.fields:
|
||||||
|
if f['name'].lower() not in fields:
|
||||||
|
names.append(f['name'])
|
||||||
|
fields.add(f['name'].lower())
|
||||||
|
if downcase:
|
||||||
|
return list(fields)
|
||||||
|
return names
|
||||||
|
|
||||||
# Find
|
# Find
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
|
@ -222,17 +237,11 @@ where mid in %s and flds like ? escape '\\'""" % (
|
||||||
extra = "not" if isNeg else ""
|
extra = "not" if isNeg else ""
|
||||||
self.lims['fact'].append("id %s in %s" % (extra, ids2str(fids)))
|
self.lims['fact'].append("id %s in %s" % (extra, ids2str(fids)))
|
||||||
|
|
||||||
def _fieldNames(self):
|
|
||||||
fields = set()
|
|
||||||
for m in self.deck.models().values():
|
|
||||||
fields.update([f['name'].lower() for f in m.fields])
|
|
||||||
return list(fields)
|
|
||||||
|
|
||||||
# Most of this function was written by Marcus
|
# Most of this function was written by Marcus
|
||||||
def _parseQuery(self):
|
def _parseQuery(self):
|
||||||
tokens = []
|
tokens = []
|
||||||
res = []
|
res = []
|
||||||
allowedfields = self._fieldNames()
|
allowedfields = fieldNames(self.deck)
|
||||||
def addSearchFieldToken(field, value, isNeg):
|
def addSearchFieldToken(field, value, isNeg):
|
||||||
if field.lower() in allowedfields:
|
if field.lower() in allowedfields:
|
||||||
res.append((field + ':' + value, isNeg, SEARCH_FIELD))
|
res.append((field + ':' + value, isNeg, SEARCH_FIELD))
|
||||||
|
|
Loading…
Reference in a new issue