generalise findByFieldName: filter included
This commit is contained in:
parent
b87ef60984
commit
67b8998da8
1 changed files with 13 additions and 2 deletions
15
formfield.py
15
formfield.py
|
@ -20,6 +20,7 @@ The information stored for the fields are:
|
|||
import subprocess as cmd
|
||||
import os.path
|
||||
import fdfgen
|
||||
import readformdata
|
||||
|
||||
|
||||
class FormField():
|
||||
|
@ -331,19 +332,29 @@ class FormField():
|
|||
self[info] = value
|
||||
|
||||
@staticmethod
|
||||
def findByFieldName(fieldList, fieldName):
|
||||
def findByFieldName(fieldList, fieldName,
|
||||
include=(lambda x: (readformdata.NON_FORMFIELD
|
||||
not in x))):
|
||||
"""Return a FormField out of a list given the searched fieldName.
|
||||
|
||||
If there are several fields with this fieldName,
|
||||
the first one is returned. This should not be the case though.
|
||||
|
||||
Attributes:
|
||||
fieldList ([FormField]): list of formfields to search in
|
||||
fieldName (str): the fieldName looked for
|
||||
include (fct: FormField -> Bool):
|
||||
fct. that returns True if the argument should be looked for
|
||||
Default: only use FormFields that do not have the info
|
||||
NON_FORMFIELD.
|
||||
|
||||
Raises:
|
||||
KeyError: if no such FieldName exist.
|
||||
|
||||
"""
|
||||
for f in fieldList:
|
||||
try:
|
||||
if f["FieldName"] == fieldName:
|
||||
if include(f) and f["FieldName"] == fieldName:
|
||||
return f
|
||||
except KeyError:
|
||||
pass # should not happen but who knows?
|
||||
|
|
Loading…
Reference in a new issue