add search in FormField lists for FieldName

This commit is contained in:
Bela 2018-02-16 13:13:38 +01:00
parent dd8ea4088e
commit 3c836c4f29

View file

@ -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.")