[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/Formulator - CompositeWidget.py:1.1.4.1 Errors.py:1.1.4.1 Field.py:1.1.4.1 FieldRegistry.py:1.1.4.1 Form.py:1.1.4.1 ICompositeWidget.py:1.1.4.1 IField.py:1.1.4.1 IInstanceFactory.py:1.1.4.1 IPropertyFieldAdapter.py:1.1.4.1 ISimpleRegistry.py:1.1.4.1 IValidator.py:1.1.4.1 IWidget.py:1.1.4.1 PropertyFieldAdapter.py:1.1.4.1 SimpleRegistry.py:1.1.4.1 Validator.py:1.1.4.1 ValidatorRegistry.py:1.1.4.1 Widget.py:1.1.4.1 __init__.py:1.1.4.1 formulator-meta.zcml:1.1.4.1 formulator.zcml:1.1.4.1 metaConfigure.py:1.1.4.1
Stephan Richter
srichter@cbu.edu
Mon, 1 Apr 2002 21:10:21 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/App/Formulator
In directory cvs.zope.org:/tmp/cvs-serv6377/Formulator
Added Files:
Tag: Zope-3x-branch
CompositeWidget.py Errors.py Field.py FieldRegistry.py Form.py
ICompositeWidget.py IField.py IInstanceFactory.py
IPropertyFieldAdapter.py ISimpleRegistry.py IValidator.py
IWidget.py PropertyFieldAdapter.py SimpleRegistry.py
Validator.py ValidatorRegistry.py Widget.py __init__.py
formulator-meta.zcml formulator.zcml metaConfigure.py
Log Message:
Issue 25: Resolved by janko & srichter
This checkin fixes all the license headers of all the files that needed
fixing it. :) This was made possible by Janko Hauser's script, which is now
available in the ZopeRoot/utilities directory.
Also, cleaned up the Formualtor tag insanity!
=== Added File Zope3/lib/python/Zope/App/Formulator/CompositeWidget.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""
$Id: CompositeWidget.py,v 1.1.4.1 2002/04/02 02:10:15 srichter Exp $
"""
from ICompositeWidget import ICompositeWidget
from Widget import Widget
class CompositeWidget(Widget):
""" """
__implements__ = Widget.__implements__, ICompositeWidget
# Page template that is ised to lay out sub-widgets
template = None
# List of Sub-Widgets
widgets = None
def render(self, REQUEST):
""" """
return apply(self.template, (REQUEST,))
def render_hidden(self, REQUEST):
""" """
return apply(self.template, (REQUEST,), {'hidden': 1})
def setWidget(self, name, widget):
""" """
if self.widgets is None:
self.widgets = {}
self.widgets[name] = widget
def getWidget(self, name, _default=None):
""" """
if name in self.widgets.keys():
return self.widgets[name]
else:
return _default
def getWidgets(self):
""" """
return self.widgets
=== Added File Zope3/lib/python/Zope/App/Formulator/Errors.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""
Exception Classes for Formulator
$Id: Errors.py,v 1.1.4.1 2002/04/02 02:10:15 srichter Exp $
"""
# These classes are placed here so that they can be imported into TTW Python
# scripts. To do so, add the following line to your Py script:
# from Products.Formulator.Errors import ValidationError, FormValidationError
class FormValidationError(Exception):
def __init__(self, errors, result):
Exception.__init__(self, "Form Validation Error")
self.errors = errors
self.result = result
class ValidationError(Exception):
def __init__(self, errorKey, field):
Exception.__init__(self, errorKey)
self.errorKey = errorKey
self.fieldId = field.id
self.field = field
self.errorText = field.getErrorMessage(errorKey)
=== Added File Zope3/lib/python/Zope/App/Formulator/Field.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""
$Id: Field.py,v 1.1.4.1 2002/04/02 02:10:15 srichter Exp $
"""
from Persistence import Persistent
from IField import IField
from Zope.App.Formulator.Errors import ValidationError
from IInstanceFactory import IInstanceFactory
class Field(Persistent):
"""Base class of all fields.
A field is an object consisting of a widget and a validator.
"""
__implements__ = (
IField,
IInstanceFactory
)
propertyNames = ('id', 'validator', 'default', 'title', 'description',
'required')
id = None
validator = None
default = None
title = 'Field Title'
description = 'Field Description'
required = 0
def __init__(self, context=None, **kw):
self.realize(context)
for name in self.propertyNames:
if name in kw.keys():
setattr(self, name, kw[name])
def getErrorMessage(self, name):
try:
return self.validator.getMessage(name)
except KeyError:
if name in self.validator.messageNames:
return getattr(self.validator, name)
else:
return "Unknown error: %s" % name
############################################################
# Implementation methods for interface
# Zope.App.Formulator.IField.
def getValidator(self):
'''See interface IField'''
return self.validator
def hasValue(self, id):
'''See interface IField'''
if id in self.propertyNames:
return 1
else:
return 0
def getValue(self, id, _default=None):
'''See interface IField'''
if id in self.propertyNames:
return getattr(self, id)
else:
return _default
def isRequired(self):
'''See interface IField'''
return hasattr(self, 'required') and getattr(self, 'required')
def getErrorNames(self):
'''See interface IField'''
return self.validator.messageNames
def getTales(self, id):
'''See interface IField'''
raise NotImplemented
def isTALESAvailable(self):
'''See interface IField'''
raise NotImplemented
def getOverride(self, id):
'''See interface IField'''
raise NotImplemented
#
############################################################
############################################################
# Implementation methods for interface
# Zope.App.Formulator.IInstanceFactory.
def __call__(self, context):
'''See interface IInstanceFactory'''
self.realize(context)
return self
def getContext(self):
'''See interface IInstanceFactory'''
return self.context
def realize(self, context):
'''See interface IInstanceFactory'''
self.context = context
#
############################################################
=== Added File Zope3/lib/python/Zope/App/Formulator/FieldRegistry.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""
$Id: FieldRegistry.py,v 1.1.4.1 2002/04/02 02:10:15 srichter Exp $
"""
from SimpleRegistry import SimpleRegistry
from ISimpleRegistry import ISimpleRegistry
from IField import IField
class IFieldRegistry(ISimpleRegistry):
"""
The Field Registry manages a list of all the fields available in Zope. A
registry is useful at this point, since fields can be initialized and
registered by many places.
Note that it does not matter whether we have classes or instances as
fields. If the fields are instances, they must implement
IInstanceFactory.
"""
pass
class FieldRegistry(SimpleRegistry):
""" """
__implements__ = (IFieldRegistry,)
FieldRegistry = FieldRegistry(IField)
registerField = FieldRegistry.register
getField = FieldRegistry.get
=== Added File Zope3/lib/python/Zope/App/Formulator/Form.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""
$Id: Form.py,v 1.1.4.1 2002/04/02 02:10:15 srichter Exp $
"""
from Zope.Publisher.Browser.AttributePublisher \
import AttributePublisher
#from IForm import IForm
from Zope.ComponentArchitecture import getRequestView
from Zope.App.Formulator.IPropertyFieldAdapter import IPropertyFieldAdapter
from Zope.App.Formulator.Errors import ValidationError
from Zope.ComponentArchitecture import getAdapter
class Form(AttributePublisher):
"""Form base class.
"""
__implements__ = AttributePublisher.__implements__#, IForm
name = 'Form Name' # for use by javascript
title = 'This is a form'
description = ''
method = 'post'
enctype = ''
_fieldViewNames = []
template = None
def __init__(self, context):
"""Initialize form.
"""
self._context = context
self._widgets = []
def index(self, REQUEST, **kw):
""" """
return apply(self.template, (REQUEST,), kw)
def action(self, REQUEST):
""" """
errors = []
values = {}
for widget in self.getFieldViews(REQUEST):
value = widget.getValueFromRequest(REQUEST)
field = widget.getContext()
try:
values[field.id] = field.getValidator().validate(field, value)
except ValidationError, err:
errors.append(err)
if errors == []:
for widget in self.getFieldViews(REQUEST):
field = widget.getContext()
getAdapter(field, IPropertyFieldAdapter).setPropertyInContext(values[field.id])
return self.index(REQUEST, errors=errors)
def getFieldViews(self, REQUEST):
""" """
views = []
context = self.getContext()
for name in self._fieldViewNames:
views.append(getRequestView(context, name, REQUEST))
return views
def getContext(self):
""" """
return self._context
=== Added File Zope3/lib/python/Zope/App/Formulator/ICompositeWidget.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""
$Id: ICompositeWidget.py,v 1.1.4.1 2002/04/02 02:10:15 srichter Exp $
"""
from IWidget import IWidget
class ICompositeWidget(IWidget):
""" """
=== Added File Zope3/lib/python/Zope/App/Formulator/IField.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
from Interface import Interface
class IField(Interface):
"""
"""
def getValidator():
"""Return the validator of this field."""
def getContext():
"""Return the context object of the field."""
def hasValue(id):
"""Return true if the field defines such a value.
"""
def getValue(id):
"""Get value for id."""
def getOverride(id):
"""Get override method for id (not wrapped)."""
def getTales(id):
"""Get tales expression method for id."""
def isRequired():
"""Check whether this field is required (utility function)
"""
def getErrorNames():
"""Get error messages.
"""
def isTALESAvailable():
"""Return true only if TALES is available.
"""
=== Added File Zope3/lib/python/Zope/App/Formulator/IInstanceFactory.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""
$Id: IInstanceFactory.py,v 1.1.4.1 2002/04/02 02:10:15 srichter Exp $
"""
from Interface import Interface
class IInstanceFactory(Interface):
"""
If the Instance Factory is implemented by an object, then this object
can be used as factory for other components, such as Views.
"""
def realize(context):
"""
Relaizes an instance in a particular context/evironment. This
method basically replaces __init__(context) for class-based
factories.
"""
def __call__(context):
"""
Basically calls realize(context). However it must be implemented
too, so that the factory is callable This method has to return the
produced object.
"""
def getContext():
"""
Get the context of the realized instance.
"""
=== Added File Zope3/lib/python/Zope/App/Formulator/IPropertyFieldAdapter.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""
$Id: IPropertyFieldAdapter.py,v 1.1.4.1 2002/04/02 02:10:15 srichter Exp $
"""
from Interface import Interface
class IPropertyFieldAdapter(Interface):
"""
"""
def setPropertyInContext(value):
""" """
def getPropertyInContext():
""" """
=== Added File Zope3/lib/python/Zope/App/Formulator/ISimpleRegistry.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""
$Id: ISimpleRegistry.py,v 1.1.4.1 2002/04/02 02:10:15 srichter Exp $
"""
from Interface import Interface
class ISimpleRegistry(Interface):
"""
The Simple Registry is minimal collection of registered objects. This can
be useful, when it is expected that objects of a particular type are added
from many places in the system (through 3rd party products for example).
A good example for this are the Formulator fields. While the basic types
are defined inside the Formulator tree, other parties might add many
more later on in their products, so it is useful to provide a registry via
ZCML that allows to collect these items.
There is only one constraint on the objects. They all must implement a
particular interface specified during the initialization of the registry.
Note that it does not matter whether we have classes or instances as
objects. If the objects are instances, they must implement simply
IInstanceFactory.
"""
def register(name, object):
"""
Registers the object under the id name.
"""
def getF(name):
"""
This returns the object with id name.
"""
=== Added File Zope3/lib/python/Zope/App/Formulator/IValidator.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""
$Id: IValidator.py,v 1.1.4.1 2002/04/02 02:10:15 srichter Exp $
"""
from Interface import Interface
class IValidator(Interface):
"""A field validator provides the functionality to verify the
input data on the server.
This class will be initialized as a singleton.
"""
def validate(field, value):
"""Validate the value, knowing the field.
"""
def raiseError(errorKey, field):
"""Raises the error, if the validation fails.
"""
=== Added File Zope3/lib/python/Zope/App/Formulator/IWidget.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""
$Id: IWidget.py,v 1.1.4.1 2002/04/02 02:10:15 srichter Exp $
"""
from Interface import Interface
class IWidget(Interface):
"""Generically describes the behavior of a widget.
The widget defines a list of propertyNames, which describes
what properties of the widget are available to use for
constructing the widget render output.
Note that this level must be still presentation independent.
"""
def getValue(name):
"""Look up a Widget setting (value) by name."""
def getContext():
"""Get the context of the widget, namely the Field."""
def render():
"""Render the widget. This will return the representation the
client will understand."""
def render_hidden():
"""Render the widget as a hidden field. This will return the
representation the client will understand."""
=== Added File Zope3/lib/python/Zope/App/Formulator/PropertyFieldAdapter.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""
$Id: PropertyFieldAdapter.py,v 1.1.4.1 2002/04/02 02:10:15 srichter Exp $
"""
from IPropertyFieldAdapter import IPropertyFieldAdapter
from Zope.App.Formulator.Errors import ValidationError
class PropertyFieldAdapter:
""" """
__implements__ = IPropertyFieldAdapter
def __init__(self, context):
""" """
self.context = context
def setPropertyInContext(self, value):
""" """
field = self.getContext()
method = getattr(field.getContext(),
'set'+field.id[0].capitalize()+field.id[1:], None)
apply(method, (value,))
def getPropertyInContext(self):
""" """
field = self.getContext()
method = getattr(field.getContext(),
'get'+field.id[0].capitalize()+field.id[1:], None)
return apply(method, ())
def getContext(self):
""" """
return self.context
=== Added File Zope3/lib/python/Zope/App/Formulator/SimpleRegistry.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""
$Id: SimpleRegistry.py,v 1.1.4.1 2002/04/02 02:10:15 srichter Exp $
"""
from Zope.Configuration.name import resolve
from ISimpleRegistry import ISimpleRegistry
from types import StringTypes, ListType, TupleType
ListTypes = (TupleType, ListType)
class ZopeDuplicateRegistryEntryError(Exception):
"""
This Error is raised when the user tries to add an object with
a name that already exists in the registry. Therefore,
overwriting is not allowed.
"""
def __init__(self, name):
"""Initializes Error"""
self.name = name
def __str__(self):
"""Returns string representation of Error"""
return "The name '%s' is already defined in this registry." \
%self.name
class ZopeIllegalInterfaceError(Exception):
"""
This Error is thrown, when the passed object does not implement
the specified interface.
"""
def __init__(self, name, interface):
"""Initalize Error"""
self.name = name
self.interface = interface
def __str__(self):
"""Returns string representation of Error"""
return ( "The object with name " + self.name + " does not implement "
"the interface " + self.interface.__name__ + "." )
class SimpleRegistry:
""" """
__implements__ = (ISimpleRegistry,)
def __init__(self, interface):
"""Initialize registry"""
self.objects = {}
self.interface = interface
############################################################
# Implementation methods for interface
# Zope.App.Formulator.ISimpleRegistry
def register(self, name, object):
'''See interface ISimpleRegistry'''
if name in self.objects.keys():
raise ZopeDuplicateRegistryEntryError(name)
# XXX Find the right Interface tools to do that; unfortunately,
# I have not found them
# Check whether the object implements the right interface.
# Note, that we do *not* know whether the object is an instance
# or a class (or worse a Persistent class)
if hasattr(object, '__implements__') and \
( self.interface == object.__implements__ or \
( type(object.__implements__) in ListTypes and
self.interface in object.__implements__ ) ):
self.objects[name] = object
else:
raise ZopeIllegalInterfaceError(name, self.interface)
return []
def get(self, name):
'''See interface ISimpleRegistry'''
if name in self.objects.keys():
return self.objects[name]
else:
return None
#
############################################################
=== Added File Zope3/lib/python/Zope/App/Formulator/Validator.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""
$Id: Validator.py,v 1.1.4.1 2002/04/02 02:10:15 srichter Exp $
"""
from Zope.App.Formulator.Errors import ValidationError
from IValidator import IValidator
from IInstanceFactory import IInstanceFactory
class Validator:
"""Validates input and possibly transforms it to output.
"""
__implements__ = (
IValidator,
IInstanceFactory
)
propertyNames = ['externalValidator']
externalValidator = None
messageNames = ['externalValidatorFailed']
externalValidatorFailed = "The input failed the external validator."
def __init__(self, **kw):
"""Initialize the Validator."""
for name in self.propertyNames:
if name in kw.keys():
setattr(self, name, kw[name])
def getMessage(self, name):
""" """
if name in self.messageNames:
return getattr(self, name)
############################################################
# Implementation methods for interface
# Zope.App.Formulator.IValidator.
def raiseError(self, errorKey, field):
'''See interface IValidator'''
raise ValidationError(errorKey, field)
def validate(self, field, value):
'''See interface IValidator'''
pass
#
############################################################
############################################################
# Implementation methods for interface
# Zope.App.Formulator.IInstanceFactory.
def __call__(self, context):
'''See interface IInstanceFactory'''
self.realize(context)
return self
def getContext(self):
'''See interface IInstanceFactory'''
return self.context
def realize(self, context):
'''See interface IInstanceFactory'''
self.context = context
#
############################################################
=== Added File Zope3/lib/python/Zope/App/Formulator/ValidatorRegistry.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""
$Id: ValidatorRegistry.py,v 1.1.4.1 2002/04/02 02:10:15 srichter Exp $
"""
from SimpleRegistry import SimpleRegistry
from ISimpleRegistry import ISimpleRegistry
from IValidator import IValidator
class IValidatorRegistry(ISimpleRegistry):
"""
Note that it does not matter whether we have classes or instances as
validators. If the validaotrs are instances, they must implement
IInstanceFactory.
"""
pass
class ValidatorRegistry(SimpleRegistry):
""" """
__implements__ = (IValidatorRegistry,)
ValidatorRegistry = ValidatorRegistry(IValidator)
registerValidator = ValidatorRegistry.register
getValidator = ValidatorRegistry.get
=== Added File Zope3/lib/python/Zope/App/Formulator/Widget.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""
$Id: Widget.py,v 1.1.4.1 2002/04/02 02:10:15 srichter Exp $
"""
from IWidget import IWidget
class Widget(object):
"""I do not know what will be in this class, but it provides
an extra layer.
"""
__implements__ = IWidget
propertyNames = []
def __init__(self, field):
""" """
self._field = field
def getValue(self, name):
""" """
if name in self.propertyNames:
return getattr(self, name, None)
def getContext(self):
""" """
return self._field
def render(self):
""" """
raise NotImplemented
def render_hidden(self):
""" """
raise NotImplemented
=== Added File Zope3/lib/python/Zope/App/Formulator/__init__.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""
$Id: __init__.py,v 1.1.4.1 2002/04/02 02:10:15 srichter Exp $
"""
from FieldRegistry import registerField, getField
from ValidatorRegistry import registerValidator, getValidator
=== Added File Zope3/lib/python/Zope/App/Formulator/formulator-meta.zcml ===
<zopeConfigure xmlns='http://namespaces.zope.org/zope'>
<directives namespace="http://namespaces.zope.org/formulator">
<directive name="registerField" attributes="name, field"
handler="Zope.App.Formulator.metaConfigure.field" />
<directive name="registerValidator" attributes="name, validator"
handler="Zope.App.Formulator.metaConfigure.validator" />
</directives>
</zopeConfigure>
=== Added File Zope3/lib/python/Zope/App/Formulator/formulator.zcml ===
<zopeConfigure
xmlns='http://namespaces.zope.org/zope'
xmlns:security='http://namespaces.zope.org/security'
>
<include package="Zope.App.Formulator" file="formulator-meta.zcml" />
<include package="Zope.App.Formulator.Fields" file="fields.zcml" />
<include package="Zope.App.Formulator.Validators" file="validators.zcml" />
<include package="Zope.App.Formulator.Widgets" file="widgets.zcml" />
<adapter factory="Zope.App.Formulator.PropertyFieldAdapter."
provides="Zope.App.Formulator.IPropertyFieldAdapter."
for="Zope.App.Formulator.IField." />
<security:protectClass
name=".Field."
permission_id="Zope.View"
interface=".IField." />
<security:protectClass
name=".Form."
permission_id="Zope.View"
methods="index, action, getFieldViews, getContext" />
</zopeConfigure>
=== Added File Zope3/lib/python/Zope/App/Formulator/metaConfigure.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""
$Id: metaConfigure.py,v 1.1.4.1 2002/04/02 02:10:15 srichter Exp $
"""
from Zope.Configuration.Action import Action
from FieldRegistry import registerField
from ValidatorRegistry import registerValidator
def field(_context, name, field):
"""
Note that most applications return an actual Action at this point;
however, the field registry is requred during the startup, so we
need to initialize it now.
"""
field = _context.resolve(field)
registerField(name, field)
return []
def validator(_context, name, validator):
"""
Note that most applications return an actual Action at this point;
however, the validator registry is requred during the startup, so we
need to initialize it now.
"""
validator = _context.resolve(validator)
registerValidator(name, validator)
return []