diff --git a/reporter/interfaces.py b/reporter/interfaces.py index 9eed2be..b5254a2 100644 --- a/reporter/interfaces.py +++ b/reporter/interfaces.py @@ -26,46 +26,6 @@ import zope from zope.interface import Interface, Attribute -# iterable stuff for batching, sorting, filtering of results - - -class IBatch(Interface): - """ Represents a part (sort of a slice) of an iterable. - """ - - iterable = Attribute(u'The iterable this batch belongs to') - - start = Attribute(u'The current start index of the batch in the parent iterable') - - def __getitem__(idx): - """ Return the item at index idx on the current page. - """ - - def next(): - """ Return the next item on the current page. Raise StopIteration if - the end of the batch is reached. - """ - - def __len__(): - """ Return the number of items on the current page. - """ - - def getIndexRelative(relativePageNumber): - """ Return the absolute page index based on the current page of - the batch object. - Using +1 or -1 retrieves the next or previous batch. - If a page before the first one is addressed return 0, - if a page after the last one is addressed return the index - of the last page. - """ - - def getIndexAbsolute(pageNumber): - """ Return the absolute page index. - 0 addresses the first batch page, -1 the last. - Return None if the corresponding page does not exist. - """ - - # result sets, rows, cells... class IResultSet(Interface): @@ -123,3 +83,42 @@ class IDataSource(Interface): """ Return an iterable that provides the data to be evaluated. """ + +# iterable stuff for batching, sorting, filtering of results + +class IBatch(Interface): + """ Represents a part (sort of a slice) of an iterable. + """ + + iterable = Attribute(u'The iterable this batch belongs to') + + start = Attribute(u'The current start index of the batch in the parent iterable') + + def __getitem__(idx): + """ Return the item at index idx on the current page. + """ + + def next(): + """ Return the next item on the current page. Raise StopIteration if + the end of the batch is reached. + """ + + def __len__(): + """ Return the number of items on the current page. + """ + + def getIndexRelative(relativePageNumber): + """ Return the absolute page index based on the current page of + the batch object. + Using +1 or -1 retrieves the next or previous batch. + If a page before the first one is addressed return 0, + if a page after the last one is addressed return the index + of the last page. + """ + + def getIndexAbsolute(pageNumber): + """ Return the absolute page index. + 0 addresses the first batch page, -1 the last. + Return None if the corresponding page does not exist. + """ + diff --git a/reporter/resultset.py b/reporter/resultset.py index 46a488b..8c26b2d 100644 --- a/reporter/resultset.py +++ b/reporter/resultset.py @@ -65,8 +65,8 @@ class Row(object): schema = self.resultSet.schema if schema is None: return {} - return dict([(f.__name__, getattr(self.context, f.__name__)) - for f in schema.fields]) + for f in schema.fields: + yield Cell(f, getattr(self.context, f.__name__), self) class ResultSet(object): @@ -74,14 +74,12 @@ class ResultSet(object): implements(IResultSet) adapts(IDataSource) + schema = None + view = None + def __init__(self, context): self.context = context - _schema = None - def setSchema(self, schema): self._schema = schema - def getSchema(self): return self._schema - schema = property(getSchema, setSchema) - @property def rows(self): for o in iter(self.context):