[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/Formulator - Field.py:1.1.4.1.14.1 Form.py:1.1.4.1.14.1 IField.py:1.1.4.1.14.1 IInstanceFactory.py:1.1.4.1.14.1 IWidget.py:1.1.4.1.14.1 PropertyFieldAdapter.py:1.1.4.1.14.1 Validator.py:1.1.4.1.14.1 Widget.py:1.1.4.1.14.1

Jim Fulton jim@zope.com
Wed, 29 May 2002 11:10:05 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/App/Formulator
In directory cvs.zope.org:/tmp/cvs-serv12181/lib/python/Zope/App/Formulator

Modified Files:
      Tag: Zope3InWonderland-branch
	Field.py Form.py IField.py IInstanceFactory.py IWidget.py 
	PropertyFieldAdapter.py Validator.py Widget.py 
Log Message:
- Added permission_id attribute to adapter and utility directives.

- Got rid of old getView, getResource, and getDefaultViewName.
  Renamed getRequestView to getView (and so on).

  Changed view interface to use context, rather than getContext.

  Introduced notion of presentation types (e.g. IBrowserPresentation, 
  which is cleaner than IBrowserPublisher).

- Began converting to get/queryFoo, which is much nicer.

- Many formatting fixups.



=== Zope3/lib/python/Zope/App/Formulator/Field.py 1.1.4.1 => 1.1.4.1.14.1 ===
 # 
 ##############################################################################
-"""
-
-$Id$
-"""
-
-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
-    #
-    ############################################################
+"""
+
+$Id$
+"""
+
+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 realize(self, context):
+        '''See interface IInstanceFactory'''
+        self.context = context
+    #
+    ############################################################


=== Zope3/lib/python/Zope/App/Formulator/Form.py 1.1.4.1 => 1.1.4.1.14.1 ===
 # 
 ##############################################################################
-"""
-
-$Id$
-"""
-
-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
+"""
+
+$Id$
+"""
+
+from Zope.Publisher.Browser.BrowserView import BrowserView
+#from IForm import IForm
+from Zope.ComponentArchitecture import getView
+from Zope.App.Formulator.IPropertyFieldAdapter import IPropertyFieldAdapter
+from Zope.App.Formulator.Errors import ValidationError
+from Zope.ComponentArchitecture import getAdapter
+
+
+class Form(BrowserView):
+    """Form base class.
+    """
+
+    name = 'Form Name'     # for use by javascript
+    title = 'This is a form'
+    description = ''
+    method = 'post'
+    enctype = ''
+
+    _fieldViewNames = []
+    template = None
+
+
+    def __init__(self, *args):
+        """Initialize form.
+        """
+        super(Form, self).__init__(*args)
+        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.context
+            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.context
+                getAdapter(field, IPropertyFieldAdapter
+                           ).setPropertyInContext(values[field.id])
+
+        return self.index(REQUEST, errors=errors)
+
+
+    def getFieldViews(self, REQUEST):
+        """ """
+        views = []
+        context = self.context
+        for name in self._fieldViewNames:
+            views.append(getView(context, name, REQUEST))
+        return views


=== Zope3/lib/python/Zope/App/Formulator/IField.py 1.1.4.1 => 1.1.4.1.14.1 ===
 # 
 ##############################################################################
-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.
-        """
-
+from Zope.ComponentArchitecture.IContextDependent import IContextDependent
+
+class IField(IContextDependent):
+    """
+    """
+
+    def getValidator():
+        """Return the validator of this 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.
+        """
+


=== Zope3/lib/python/Zope/App/Formulator/IInstanceFactory.py 1.1.4.1 => 1.1.4.1.14.1 ===
 # 
 ##############################################################################
-"""
-
-$Id$
-"""
-
-
-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.
-        """
+"""
+
+$Id$
+"""
+
+from Zope.ComponentArchitecture.IContextDependent import IContextDependent
+
+class IInstanceFactory(IContextDependent):
+    """
+    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.
+        """
+    


=== Zope3/lib/python/Zope/App/Formulator/IWidget.py 1.1.4.1 => 1.1.4.1.14.1 ===
 # 
 ##############################################################################
-"""
-
-$Id$
-"""
-
-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."""
+"""
+
+$Id$
+"""
+from Zope.ComponentArchitecture.IContextDependent import IContextDependent
+
+class IWidget(IContextDependent):
+    """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 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."""


=== Zope3/lib/python/Zope/App/Formulator/PropertyFieldAdapter.py 1.1.4.1 => 1.1.4.1.14.1 ===
 
 
-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
+class PropertyFieldAdapter:
+    """ """
+
+    __implements__ = IPropertyFieldAdapter
+
+
+    def __init__(self, context):
+        """ """
+        self.context = context
+
+
+    def setPropertyInContext(self, value):
+        """ """
+        field = self.context
+        method = getattr(field.context,
+                        'set'+field.id[0].capitalize()+field.id[1:], None)
+        apply(method, (value,))
+
+
+    def getPropertyInContext(self):
+        """ """
+        field = self.context
+        method = getattr(field.context,
+                        'get'+field.id[0].capitalize()+field.id[1:], None)
+        return apply(method, ())


=== Zope3/lib/python/Zope/App/Formulator/Validator.py 1.1.4.1 => 1.1.4.1.14.1 ===
         self.realize(context)
         return self
-    
-
-    def getContext(self):
-        '''See interface IInstanceFactory'''
-        return self.context
-
 
     def realize(self, context):
         '''See interface IInstanceFactory'''


=== Zope3/lib/python/Zope/App/Formulator/Widget.py 1.1.4.1 => 1.1.4.1.14.1 ===
 # 
 ##############################################################################
-"""
-
-$Id$
-"""
-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
+"""
+
+$Id$
+"""
+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.context = field
+
+    def getValue(self, name):
+        """ """
+        if name in self.propertyNames:
+            return getattr(self, name, None)
+
+
+    def render(self):
+        """ """
+        raise NotImplemented
+
+
+    def render_hidden(self):
+        """ """
+        raise NotImplemented