diff --git a/composer/report/README.txt b/composer/report/README.txt new file mode 100644 index 0000000..e145536 --- /dev/null +++ b/composer/report/README.txt @@ -0,0 +1,11 @@ +================= +Report Management +================= + + ($Id$) + + >>> from zope import component + >>> from cybertools.composer.report.base import ReportManager, Report + + >>> manager = ReportManager() + diff --git a/composer/report/__init__.py b/composer/report/__init__.py new file mode 100644 index 0000000..4bc90fb --- /dev/null +++ b/composer/report/__init__.py @@ -0,0 +1,4 @@ +""" +$Id$ +""" + diff --git a/composer/report/base.py b/composer/report/base.py new file mode 100644 index 0000000..66ff9a5 --- /dev/null +++ b/composer/report/base.py @@ -0,0 +1,67 @@ +# +# Copyright (c) 2010 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 classes for report management. + +$Id$ +""" + +from zope.interface import implements + +from cybertools.composer.base import Component, Element, Compound +from cybertools.composer.base import Template +from cybertools.composer.report.interfaces import IReportManager, IReport +from cybertools.util.jeep import Jeep +from cybertools.util.randomname import generateName + + +class ReportManager(object): + + implements(IReportManager) + + reports = manager = None + reportsFactory = dict + + def getManager(self): + return self.manager + + def addReport(self, report): + if self.reports is None: + self.reports = self.reportsFactory() + id = report.identifier + if not id: + id = generateName(self.checkId) + report.identifier = id + self.reports[id] = report + return report + + def checkId(self, id): + return id not in self.reports.keys() + + +class Report(Template): + + implements(IReport) + + name = identifier = u'' + type = 'generic' + manager = None + + def __init__(self, name): + self.name = name diff --git a/composer/report/configure.zcml b/composer/report/configure.zcml new file mode 100644 index 0000000..4e47e39 --- /dev/null +++ b/composer/report/configure.zcml @@ -0,0 +1,8 @@ + + + + + diff --git a/composer/report/instance.py b/composer/report/instance.py new file mode 100644 index 0000000..33606a5 --- /dev/null +++ b/composer/report/instance.py @@ -0,0 +1,57 @@ +# +# Copyright (c) 2010 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 +# + +""" +Report instance and related classes. + +$Id$ +""" + +from string import Template +from zope import component +from zope.interface import implements +from zope.publisher.browser import TestRequest +try: + from zope.traversing.browser.absoluteurl import absoluteURL + zope29 = False +except ImportError: + from zope.app.traversing.browser.absoluteurl import absoluteURL + from Acquisition import aq_parent, aq_inner + zope29 = True + +from cybertools.composer.instance import Instance +from cybertools.composer.interfaces import IInstance +from cybertools.util.jeep import Jeep + +_not_found = object() + + +class ReportInstance(Instance): + + template = client = None + + def __init__(self, client, template, manager): + self.client = client + self.template = template + self.manager = manager + + def applyTemplate(self, **kw): + data = [] # TODO: create result set + request = data.get('request') or TestRequest() + return data + diff --git a/composer/report/interfaces.py b/composer/report/interfaces.py new file mode 100644 index 0000000..b717dfd --- /dev/null +++ b/composer/report/interfaces.py @@ -0,0 +1,73 @@ +# +# Copyright (c) 2010 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 +# + +""" +Report management. + +$Id$ +""" + +from zope.interface import Interface, Attribute +from zope.i18nmessageid import MessageFactory +from zope import schema + +from cybertools.composer.interfaces import ITemplate, IComponent +from cybertools.composer.interfaces import IInstance + +_ = MessageFactory('cybertools.composer') + + +class IReportManager(Interface): + """ A manager (or container) for complex messages. + """ + + title = schema.TextLine( + title=_(u'Title'), + description=_(u'The title of the object.'), + required=True,) + + reports = Attribute('A collection of message objects managed.') + + def addReport(report): + """ Add a report. + """ + + +class IReport(Interface): + """ A complex message that may be expanded using instance data. + """ + + identifier = schema.ASCIILine( + title=_(u'Identifier'), + description=_(u'The (internal) identifier of the report.'), + required=True,) + name = schema.ASCIILine( + title=_(u'Name'), + description=_(u'The (visible) name of the report.'), + required=True,) + title = schema.TextLine( + title=_(u'Title'), + description=_(u'The title or label of the report.'), + required=True,) + description = schema.Text( + title=_(u'Description'), + description=_(u'A brief description of the report.'), + required=False,) + + manager = Attribute('The manager of this message object') + diff --git a/composer/report/tests.py b/composer/report/tests.py new file mode 100755 index 0000000..9886053 --- /dev/null +++ b/composer/report/tests.py @@ -0,0 +1,22 @@ +# $Id$ + +import unittest, doctest +from zope.testing.doctestunit import DocFileSuite + + +class Test(unittest.TestCase): + "Basic tests." + + def testBasics(self): + pass + + +def test_suite(): + flags = doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS + return unittest.TestSuite(( + unittest.makeSuite(Test), + DocFileSuite('README.txt', optionflags=flags), + )) + +if __name__ == '__main__': + unittest.main(defaultTest='test_suite')