add utility property and function for accessing data table data as records/rows

This commit is contained in:
Helmut Merz 2015-03-16 12:10:34 +01:00
parent beff6ef2dd
commit c4ce28e239
2 changed files with 9 additions and 0 deletions

View file

@ -913,6 +913,12 @@ relates ISO country codes with the full name of the country.
>>> sorted(adapted(concepts['countries']).data.items())
[('at', ['Austria']), ('de', ['Germany'])]
>>> countries.dataAsRecords
[{'value': 'Austria', 'key': 'at'}, {'value': 'Germany', 'key': 'de'}]
>>> countries.getRowsByValue('value', 'Germany')
[{'value': 'Germany', 'key': 'de'}]
Caching
=======

View file

@ -106,6 +106,9 @@ class DataTable(AdapterBase):
result.append(item)
return result
def getRowsByValue(self, column, value):
return [r for r in self.dataAsRecords if r[column] == value]
TypeInterfaceSourceList.typeInterfaces += (IDataTable,)