From c4ce28e2396b86cda77ee4dc05eb3de078c493a8 Mon Sep 17 00:00:00 2001 From: Helmut Merz Date: Mon, 16 Mar 2015 12:10:34 +0100 Subject: [PATCH] add utility property and function for accessing data table data as records/rows --- README.txt | 6 ++++++ table.py | 3 +++ 2 files changed, 9 insertions(+) diff --git a/README.txt b/README.txt index 6ec6fc2..bbffa03 100755 --- a/README.txt +++ b/README.txt @@ -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 ======= diff --git a/table.py b/table.py index d09c194..fcece94 100644 --- a/table.py +++ b/table.py @@ -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,)