Skip to content

Commit

Permalink
support array of field names as valid source and destination names in…
Browse files Browse the repository at this point in the history
… order to support the fields of the Fluent Forever Mandarin Model Deck out-of-the-box
  • Loading branch information
Connum committed Jun 18, 2018
1 parent ec7af6c commit d8bde3f
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions anki/hanzi_colorizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,23 +86,48 @@
InvalidCharacterError)
import string

srcField = 'Hanzi'
dstField = 'Diagram'
srcField = ['Hanzi', 'Word (in Kanji/Hanzi)']
dstField = ['Diagram', 'Stroke Order Diagram 1']

kc = KanjiColorizer(config)


def modelIsCorrectType(model):
global srcField
global dstField

'''
Returns True if model has Chinese or Mandarin in the name and has both srcField
and dstField; otherwise returns False
'''
# Does the model name have Chinese or Mandarin in it?
model_name = model['name'].lower()
fields = mw.col.models.fieldNames(model)

hasValidSrcField = False
hasValidDstField = False

if isinstance(srcField, list):
for f in srcField:
if f in fields:
hasValidSrcField = True
srcField = f
break
else:
hasValidSrcField = srcField in fields

if isinstance(dstField, list):
for f in dstField:
if f in fields:
hasValidDstField = True
dstField = f
break
else:
hasValidDstField = dstField in fields

return (('chinese' in model_name or 'mandarin' in model_name) and
srcField in fields and
dstField in fields)
hasValidSrcField and
hasValidDstField)


def characters_to_colorize(s):
Expand Down

0 comments on commit d8bde3f

Please sign in to comment.