add search in FormField lists for FieldName
This commit is contained in:
parent
dd8ea4088e
commit
3c836c4f29
1 changed files with 19 additions and 0 deletions
19
formfield.py
19
formfield.py
|
@ -311,3 +311,22 @@ class FormField():
|
|||
for info, value in otherField:
|
||||
# info does not exist in self or is equal
|
||||
self[info] = value
|
||||
|
||||
@staticmethod
|
||||
def findByFieldName(fieldList, fieldName):
|
||||
"""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.
|
||||
|
||||
Raises:
|
||||
KeyError: if no such FieldName exist.
|
||||
|
||||
"""
|
||||
for f in fieldList:
|
||||
try:
|
||||
if f["FieldName"] == fieldName:
|
||||
return f
|
||||
except KeyError:
|
||||
pass # should not happen but who knows?
|
||||
raise KeyError("No field with FieldName '" + fieldName + "' exist.")
|
||||
|
|
Loading…
Reference in a new issue