work in progress: cybertools.reporter
git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@1749 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
a0a52ab055
commit
23ca7210c1
2 changed files with 44 additions and 47 deletions
|
@ -26,46 +26,6 @@ import zope
|
||||||
from zope.interface import Interface, Attribute
|
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...
|
# result sets, rows, cells...
|
||||||
|
|
||||||
class IResultSet(Interface):
|
class IResultSet(Interface):
|
||||||
|
@ -123,3 +83,42 @@ class IDataSource(Interface):
|
||||||
""" Return an iterable that provides the data to be evaluated.
|
""" 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.
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
|
@ -65,8 +65,8 @@ class Row(object):
|
||||||
schema = self.resultSet.schema
|
schema = self.resultSet.schema
|
||||||
if schema is None:
|
if schema is None:
|
||||||
return {}
|
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):
|
class ResultSet(object):
|
||||||
|
@ -74,14 +74,12 @@ class ResultSet(object):
|
||||||
implements(IResultSet)
|
implements(IResultSet)
|
||||||
adapts(IDataSource)
|
adapts(IDataSource)
|
||||||
|
|
||||||
|
schema = None
|
||||||
|
view = None
|
||||||
|
|
||||||
def __init__(self, context):
|
def __init__(self, context):
|
||||||
self.context = context
|
self.context = context
|
||||||
|
|
||||||
_schema = None
|
|
||||||
def setSchema(self, schema): self._schema = schema
|
|
||||||
def getSchema(self): return self._schema
|
|
||||||
schema = property(getSchema, setSchema)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def rows(self):
|
def rows(self):
|
||||||
for o in iter(self.context):
|
for o in iter(self.context):
|
||||||
|
|
Loading…
Add table
Reference in a new issue