create cybertools.commerce package
git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@2757 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
80ff9b8403
commit
ad42014dc7
11 changed files with 208 additions and 2 deletions
14
commerce/README.txt
Normal file
14
commerce/README.txt
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
==========================================
|
||||||
|
Commerce: Products, Customers, Orders, ...
|
||||||
|
==========================================
|
||||||
|
|
||||||
|
($Id$)
|
||||||
|
|
||||||
|
|
||||||
|
Products
|
||||||
|
========
|
||||||
|
|
||||||
|
Let's start with a Product:
|
||||||
|
|
||||||
|
>>> from cybertools.commerce.product import Product
|
||||||
|
>>> p1 = Product()
|
4
commerce/__init__.py
Normal file
4
commerce/__init__.py
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
"""
|
||||||
|
$Id$
|
||||||
|
"""
|
||||||
|
|
4
commerce/browser/__init__.py
Normal file
4
commerce/browser/__init__.py
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
"""
|
||||||
|
$Id$
|
||||||
|
"""
|
||||||
|
|
15
commerce/browser/configure.zcml
Normal file
15
commerce/browser/configure.zcml
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
<!-- $Id$ -->
|
||||||
|
|
||||||
|
<configure
|
||||||
|
xmlns="http://namespaces.zope.org/browser"
|
||||||
|
xmlns:zope="http://namespaces.zope.org/zope"
|
||||||
|
i18n_domain="cybertools.commerce">
|
||||||
|
|
||||||
|
<page
|
||||||
|
for="cybertools.commerce.interfaces.IProduct"
|
||||||
|
name="index.html"
|
||||||
|
class="cybertools.commerce.browser.product.ProductView"
|
||||||
|
permission="zope.View"
|
||||||
|
/>
|
||||||
|
|
||||||
|
</configure>
|
34
commerce/browser/product.py
Normal file
34
commerce/browser/product.py
Normal file
|
@ -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
|
||||||
|
|
40
commerce/interfaces.py
Normal file
40
commerce/interfaces.py
Normal file
|
@ -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.
|
||||||
|
"""
|
||||||
|
|
33
commerce/product.py
Normal file
33
commerce/product.py
Normal file
|
@ -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)
|
||||||
|
|
28
commerce/tests.py
Executable file
28
commerce/tests.py
Executable file
|
@ -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')
|
|
@ -23,6 +23,7 @@ $Id$
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from BTrees.OOBTree import OOBTree
|
from BTrees.OOBTree import OOBTree
|
||||||
|
from zope.cachedescriptors.property import Lazy
|
||||||
from zope.component import adapts
|
from zope.component import adapts
|
||||||
from zope.interface import implements, Interface
|
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.interfaces import IInstance
|
||||||
from cybertools.composer.schema.interfaces import IClient
|
from cybertools.composer.schema.interfaces import IClient
|
||||||
from cybertools.composer.schema.schema import FormState
|
from cybertools.composer.schema.schema import FormState
|
||||||
|
from cybertools.util.jeep import Jeep
|
||||||
|
|
||||||
|
|
||||||
class Instance(BaseInstance):
|
class Instance(BaseInstance):
|
||||||
|
@ -42,7 +44,6 @@ class Instance(BaseInstance):
|
||||||
view = None
|
view = None
|
||||||
|
|
||||||
def applyTemplate(self, *args, **kw):
|
def applyTemplate(self, *args, **kw):
|
||||||
#result = dict(__name__=self.context.__name__)
|
|
||||||
result = {}
|
result = {}
|
||||||
mode = kw.get('mode', 'view')
|
mode = kw.get('mode', 'view')
|
||||||
template = self.template
|
template = self.template
|
||||||
|
@ -59,6 +60,18 @@ class Instance(BaseInstance):
|
||||||
result[name] = value
|
result[name] = value
|
||||||
return result
|
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):
|
class Editor(BaseInstance):
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@ from zope.i18nmessageid import MessageFactory
|
||||||
from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
|
from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
|
||||||
|
|
||||||
from cybertools.composer.interfaces import ITemplate, IComponent
|
from cybertools.composer.interfaces import ITemplate, IComponent
|
||||||
|
from cybertools.composer.interfaces import IInstance as IBaseInstance
|
||||||
|
|
||||||
_ = MessageFactory('zope')
|
_ = MessageFactory('zope')
|
||||||
|
|
||||||
|
@ -257,6 +258,26 @@ class IFormState(Interface):
|
||||||
"severities.")
|
"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
|
# clients
|
||||||
|
|
||||||
class IClient(Interface):
|
class IClient(Interface):
|
||||||
|
|
|
@ -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
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
|
Loading…
Add table
Reference in a new issue