starting the cybertools.reporter package...

git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@1113 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
helmutm 2006-03-06 08:43:39 +00:00
parent ed8c66ce15
commit b258964967
11 changed files with 287 additions and 0 deletions

37
reporter/README.txt Normal file
View file

@ -0,0 +1,37 @@
Quickstart Instructions
=======================
($Id$)
>>> from zope.app import zapi
>>> from zope.app.testing import ztapi
>>> from zope.interface import directlyProvides
A Basic API for Reports and Listings
====================================
>>> from cybertools.reporter.data import DataSource
>>> from cybertools.reporter.interfaces import IResultSet
Let's start with the Person class from the example package - we will
then provide a listing of persons...
>>> from cybertools.reporter.example.contact import Person, Contacts
>>> from cybertools.reporter.example.interfaces import IContactsDataSource
>>> import time
>>> format = '%Y-%m-%d'
>>> pdata = ((u'John', u'Smith', '1956-08-01'),
... (u'David', u'Waters', '1972-12-24'),
... (u'Carla', u'Myers', '1981-10-11'))
>>> persons = DataSource([Person(f, s, time.strptime(b, format))
... for f, s, b in pdata])
>>> directlyProvides(persons, IContactsDataSource)
>>> ztapi.provideAdapter(IContactsDataSource, IResultSet, Contacts)
>>> rset = IResultSet(persons)
For the browser presentation we can also use a browser view providing
the result set with extended attributes:
>>> #rsView = zapi.getMultiAdapter((context, TestRequest()), IBrowserView)

4
reporter/__init__.py Normal file
View file

@ -0,0 +1,4 @@
"""
$Id$
"""

View file

@ -0,0 +1,4 @@
"""
$Id$
"""

8
reporter/configure.zcml Normal file
View file

@ -0,0 +1,8 @@
<!-- $Id$ -->
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:browser="http://namespaces.zope.org/browser"
i18n_domain="zope">
</configure>

View file

@ -0,0 +1 @@
<include package="cybertools.reporter" />

37
reporter/data.py Normal file
View file

@ -0,0 +1,37 @@
#
# Copyright (c) 2006 Helmut Merz helmutm@cy55.de
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
"""
Basic data / data source implementations.
$Id$
"""
from zope.interface import implements
from cybertools.reporter.interfaces import IDataSource
class DataSource(object):
implements(IDataSource)
def __init__(self, iterable):
self.data = iterable
def __iter__(self):
return iter(self.data)

View file

@ -0,0 +1,4 @@
"""
$Id$
"""

View file

@ -0,0 +1,48 @@
#
# Copyright (c) 2006 Helmut Merz helmutm@cy55.de
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
"""
A set of simple application classes for contact management to be used
as an example for the cybertools.reporter package.
$Id$
"""
from zope.component import adapts
from zope.interface import implements
from cybertools.reporter.interfaces import IResultSet
from cybertools.reporter.example.interfaces import IContactsDataSource
class Person(object):
def __init__(self, firstName, lastName, birthDate):
self.firstName = firstName
self.lastName = lastName
self.birthDate = birthDate
class Contacts(object):
implements(IResultSet)
adapts(IContactsDataSource)
def __init__(self, context):
self.context = context

View file

@ -0,0 +1,31 @@
#
# Copyright (c) 2006 Helmut Merz helmutm@cy55.de
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
"""
Interfaces for a simple contact management framework to be used
as an example for the cybertools.reporter package.
$Id$
"""
from zope.interface import Interface
class IContactsDataSource(Interface):
""" A data source marker interface for contacts.
"""

86
reporter/interfaces.py Normal file
View file

@ -0,0 +1,86 @@
#
# Copyright (c) 2006 Helmut Merz helmutm@cy55.de
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
"""
interface definitions for the reporter package.
$Id$
"""
import zope
from zope.interface import Interface, Attribute
# result set
class IResultSet(Interface):
"""A sequence of rows provided by a data source, report or
similar object, together with a schema that describes the columns
(fields, cells).
"""
schema = zope.schema.Iterable(title=u'Schema',
description=u'Collection of field specifications based '
'on the interfaces defined by zope.schema.')
rows = zope.schema.Iterable(title=u'Rows',
description=u'Sequence of row objects')
class IRow(Interface):
""" A sequence of cells containing the real data objects.
"""
cells = zope.schema.Dict(zope.schema.ASCIILine(),
title=u'Cells',
description=u'Mapping of data elements addressed by a name '
'that is the key to the mapping.')
resultSet = Attribute('The result set this row belongs to.')
class ICell(Interface):
""" A single cell of a listing or table.
"""
text = zope.schema.Text(title=u'Text',
description=u'Text to be displayed')
value = zope.schema.Object(Interface,
title=u'Value',
description=u'The real object, often identical to text.')
token = zope.schema.ASCIILine(title=u'Token',
description=u'May be used to identify a cell within'
'the result set, e.g. in forms')
row = Attribute('The row this cell belongs to.')
def sortKey():
""" Returns a value (typically a string or a sequence) that will
be used for comparing cells in order to sort rows.
"""
# data source
class IDataSource(Interface):
""" An iterable that may be used as a data source.
"""
def __iter__():
""" Return an iterable that provides the data to be evaluated.
"""

27
reporter/tests.py Executable file
View file

@ -0,0 +1,27 @@
# $Id$
import unittest
from zope.testing.doctestunit import DocFileSuite
from zope.app.testing import ztapi
from zope.interface.verify import verifyClass
from zope.interface import implements
from zope.app import zapi
from cybertools.reporter.interfaces import IResultSet, IRow, ICell
class TestReporter(unittest.TestCase):
"Basic tests for the reporter package."
def testInterfaces(self):
pass
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(TestReporter),
DocFileSuite('README.txt'),
))
if __name__ == '__main__':
unittest.main(defaultTest='test_suite')