From ad42014dc70f4147c71e0797fdce1f3872fe1877 Mon Sep 17 00:00:00 2001 From: helmutm Date: Sat, 12 Jul 2008 14:00:12 +0000 Subject: [PATCH] create cybertools.commerce package git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@2757 fd906abe-77d9-0310-91a1-e0d9ade77398 --- commerce/README.txt | 14 ++++++++++++ commerce/__init__.py | 4 ++++ commerce/browser/__init__.py | 4 ++++ commerce/browser/configure.zcml | 15 +++++++++++++ commerce/browser/product.py | 34 ++++++++++++++++++++++++++++ commerce/interfaces.py | 40 +++++++++++++++++++++++++++++++++ commerce/product.py | 33 +++++++++++++++++++++++++++ commerce/tests.py | 28 +++++++++++++++++++++++ composer/schema/instance.py | 15 ++++++++++++- composer/schema/interfaces.py | 21 +++++++++++++++++ reporter/resultset.py | 2 +- 11 files changed, 208 insertions(+), 2 deletions(-) create mode 100644 commerce/README.txt create mode 100644 commerce/__init__.py create mode 100644 commerce/browser/__init__.py create mode 100644 commerce/browser/configure.zcml create mode 100644 commerce/browser/product.py create mode 100644 commerce/interfaces.py create mode 100644 commerce/product.py create mode 100755 commerce/tests.py diff --git a/commerce/README.txt b/commerce/README.txt new file mode 100644 index 0000000..7199863 --- /dev/null +++ b/commerce/README.txt @@ -0,0 +1,14 @@ +========================================== +Commerce: Products, Customers, Orders, ... +========================================== + + ($Id$) + + +Products +======== + +Let's start with a Product: + + >>> from cybertools.commerce.product import Product + >>> p1 = Product() diff --git a/commerce/__init__.py b/commerce/__init__.py new file mode 100644 index 0000000..4bc90fb --- /dev/null +++ b/commerce/__init__.py @@ -0,0 +1,4 @@ +""" +$Id$ +""" + diff --git a/commerce/browser/__init__.py b/commerce/browser/__init__.py new file mode 100644 index 0000000..4bc90fb --- /dev/null +++ b/commerce/browser/__init__.py @@ -0,0 +1,4 @@ +""" +$Id$ +""" + diff --git a/commerce/browser/configure.zcml b/commerce/browser/configure.zcml new file mode 100644 index 0000000..6f77bb0 --- /dev/null +++ b/commerce/browser/configure.zcml @@ -0,0 +1,15 @@ + + + + + + + diff --git a/commerce/browser/product.py b/commerce/browser/product.py new file mode 100644 index 0000000..0dfe8f4 --- /dev/null +++ b/commerce/browser/product.py @@ -0,0 +1,34 @@ +# +# Copyright (c) 2008 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 browser view classes for products. + +$Id$ +""" + +from zope import component +from zope.cachedescriptors.property import Lazy + + +class ProcuctView(object): + + def __init__(self, context, request): + self.context = context + self.request = request + diff --git a/commerce/interfaces.py b/commerce/interfaces.py new file mode 100644 index 0000000..bb22c12 --- /dev/null +++ b/commerce/interfaces.py @@ -0,0 +1,40 @@ +# +# Copyright (c) 2008 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 the commerce domain like products, customers, orders, ... + +$Id$ +""" + +from zope import schema +from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm +from zope.interface import Interface, Attribute +from zope.i18nmessageid import MessageFactory + +from cybertools.util.jeep import Jeep, Term + +_ = MessageFactory('cybertools.commerce') + + +# products + +class IProduct(Interface): + """ A certain class of similar objects that may be put in a shopping cart. + """ + diff --git a/commerce/product.py b/commerce/product.py new file mode 100644 index 0000000..24458f0 --- /dev/null +++ b/commerce/product.py @@ -0,0 +1,33 @@ +# +# Copyright (c) 2008 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 +# + +""" +Product classes. + +$Id$ +""" + +from zope.interface import implements, Interface + +from cybertools.commerce.interfaces import IProduct + + +class Product(object): + + implements(IProduct) + diff --git a/commerce/tests.py b/commerce/tests.py new file mode 100755 index 0000000..7496228 --- /dev/null +++ b/commerce/tests.py @@ -0,0 +1,28 @@ +#! /usr/bin/python + +""" +Tests for the 'cybertools.commerce' package. + +$Id$ +""" + +import unittest, doctest +from zope.testing.doctestunit import DocFileSuite +from cybertools.commerce.product import Product + +class Test(unittest.TestCase): + "Basic tests." + + def testBasicStuff(self): + p = Product() + + +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') diff --git a/composer/schema/instance.py b/composer/schema/instance.py index 812aa34..aee0cf0 100644 --- a/composer/schema/instance.py +++ b/composer/schema/instance.py @@ -23,6 +23,7 @@ $Id$ """ from BTrees.OOBTree import OOBTree +from zope.cachedescriptors.property import Lazy from zope.component import adapts from zope.interface import implements, Interface @@ -30,6 +31,7 @@ from cybertools.composer.instance import Instance as BaseInstance from cybertools.composer.interfaces import IInstance from cybertools.composer.schema.interfaces import IClient from cybertools.composer.schema.schema import FormState +from cybertools.util.jeep import Jeep class Instance(BaseInstance): @@ -42,7 +44,6 @@ class Instance(BaseInstance): view = None def applyTemplate(self, *args, **kw): - #result = dict(__name__=self.context.__name__) result = {} mode = kw.get('mode', 'view') template = self.template @@ -59,6 +60,18 @@ class Instance(BaseInstance): result[name] = value return result + def getFieldInstances(self): + fieldInstances = Jeep() + template = self.template + if template is not None: + for f in template.components: + fieldInstances[f.name] = f.getFieldInstance(self) + return fieldInstances + + @Lazy + def fieldInstances(self): + return self.getFieldInstances() + class Editor(BaseInstance): diff --git a/composer/schema/interfaces.py b/composer/schema/interfaces.py index 24f3499..2a1174f 100644 --- a/composer/schema/interfaces.py +++ b/composer/schema/interfaces.py @@ -28,6 +28,7 @@ from zope.i18nmessageid import MessageFactory from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm from cybertools.composer.interfaces import ITemplate, IComponent +from cybertools.composer.interfaces import IInstance as IBaseInstance _ = MessageFactory('zope') @@ -257,6 +258,26 @@ class IFormState(Interface): "severities.") +class IInstance(IBaseInstance): + """ An instance adapter for arbitrary client objects, using a schema. + """ + + fieldInstances = Attribute('A mapping ``{fieldName: fieldInstance, ...}``.') + + +class IEditor(IInstance): + """ An instance adapter for a client object that represents the state + of all fields when editing. + """ + # TODO: make IFormState + implementations obsolete + + fieldInstances = Attribute('A mapping ``{fieldName: fieldInstance, ...}``.') + changed = Attribute('True if one of the fields has been changed') + severity = Attribute("An integer giving an overall state or error " + "code, typically the maximum of the field instances' " + "severities.") + + # clients class IClient(Interface): diff --git a/reporter/resultset.py b/reporter/resultset.py index 4e10586..f8eca7e 100644 --- a/reporter/resultset.py +++ b/reporter/resultset.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2006 Helmut Merz helmutm@cy55.de +# Copyright (c) 2008 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