[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/Formulator/Fields - Field.py:1.1.2.1 Field.pyc:1.1.2.1 IField.py:1.1.2.1 IField.pyc:1.1.2.1 IPropertyField.py:1.1.2.1 IPropertyField.pyc:1.1.2.1 PropertyField.py:1.1.2.1 PropertyField.pyc:1.1.2.1 __init__.py:1.1.2.1 __init__.pyc:1.1.2.1

Stephan Richter srichter@cbu.edu
Fri, 25 Jan 2002 09:11:08 -0500


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

Added Files:
      Tag: Zope-3x-branch
	Field.py Field.pyc IField.py IField.pyc IPropertyField.py 
	IPropertyField.pyc PropertyField.py PropertyField.pyc 
	__init__.py __init__.pyc 
Log Message:
- Initial check-in of the Formulator code
- Even though not everything works (specifically the widgets are in bad 
  shape), I am checking that stuff in, so that Jim, Martijn F. and I can
  better work together.
- The FileEdit screen (which will be checked in in a minute) uses already
  formulator.
- The validators are closed to finished.
- I think we have to rethink some of the design, simply because it is too
  hard right now to create a field and a view for a property, even though
  I provided already some handy methods. However Formulator does not 
  depend on Property-driven content objects.
- Please contact me (srichter@cbu.edu) or the Zope3 mailining list to 
  discuss issues and design.


=== Added File Zope3/lib/python/Zope/App/Formulator/Fields/Field.py ===
##############################################################################
#
# Copyright (c) 2001 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
# 
##############################################################################
"""

Revision information: $Id: Field.py,v 1.1.2.1 2002/01/25 14:11:06 srichter Exp $
"""

from Persistence import Persistent
from IField import IField
from Zope.App.Formulator.Errors import ValidationError



class Field(Persistent):
    """Base class of all fields.
    A field is an object consisting of a widget and a validator.
    """

    __implements__ = IField

    propertyNames = ['validator', 'default', 'title', 'description',
                     'property', 'isRequired']

    id = None
    validator = None
    default = None
    title = 'Field Title'
    description = 'Field Description'
    isRequired = 0


    def __init__(self, context):
        self._context = context
    

    def getContext(self):
        return self._context


    def getValidator(self):
        return self.validator
    

    def hasValue(self, id):
        """Return true if the field defines such a value.
        """
        if id in self.propertyNames:
            return 1
        else:
            return 0


    def getValue(self, id, _default=None):
        """Get value for id."""
        if id in self.propertyNames:
            return getattr(self, id)
        else:
            return _default
        
        

    def isRequired(self):
        """Check whether this field is required (utility function)
        """
        return self.has_value('isRequired') and self.get_value('isRequired')
    

    def getErrorNames(self):
        """Get error messages.
        """
        return self.validator.messageNames


    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




=== Added File Zope3/lib/python/Zope/App/Formulator/Fields/Field.pyc ===
  <Binary-ish file>

=== Added File Zope3/lib/python/Zope/App/Formulator/Fields/IField.py ===
# This software is subject to the provisions of the Zope Public License,
# Version 1.1 (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/Fields/IField.pyc ===
-í
dQ<c       s0     	 d  k  l  Z   d e  f d „  ƒ  YZ d S(   (   s	   Interfaces   IFieldc      sz    d  Z    d „  Z  d „  Z  d „  Z  d „  Z ! d „  Z % d „  Z ) d „  Z . d „  Z 3 d	 „  Z	 RS(
   s   
    c      s
     d S(   s#   Return the validator of this field.N(    (    (    (    s:   /opt/Zope3/lib/python/Zope/App/Formulator/Fields/IField.pys   getValidator s   c      s
     d S(   s'   Return the context object of the field.N(    (    (    (    s:   /opt/Zope3/lib/python/Zope/App/Formulator/Fields/IField.pys
   getContext s   c    s
     d S(   s7   Return true if the field defines such a value.
        N(    (   s   id(    (    s:   /opt/Zope3/lib/python/Zope/App/Formulator/Fields/IField.pys   hasValue s   c    s
     d S(   s   Get value for id.N(    (   s   id(    (    s:   /opt/Zope3/lib/python/Zope/App/Formulator/Fields/IField.pys   getValue s   c    s
   ! " d S(   s)   Get override method for id (not wrapped).N(    (   s   id(    (    s:   /opt/Zope3/lib/python/Zope/App/Formulator/Fields/IField.pys   getOverride! s   c    s
   % & d S(   s#   Get tales expression method for id.N(    (   s   id(    (    s:   /opt/Zope3/lib/python/Zope/App/Formulator/Fields/IField.pys   getTales% s   c      s
   ) + d S(   s@   Check whether this field is required (utility function)
        N(    (    (    (    s:   /opt/Zope3/lib/python/Zope/App/Formulator/Fields/IField.pys
   isRequired) s   c      s
   . 0 d S(   s   Get error messages.
        N(    (    (    (    s:   /opt/Zope3/lib/python/Zope/App/Formulator/Fields/IField.pys
   getErrorNames. s   c      s
   3 5 d S(   s0   Return true only if TALES is available.
        N(    (    (    (    s:   /opt/Zope3/lib/python/Zope/App/Formulator/Fields/IField.pys   isTALESAvailable3 s   (
   s   __doc__s   getValidators
   getContexts   hasValues   getValues   getOverrides   getTaless
   isRequireds
   getErrorNamess   isTALESAvailable(    (    (    s:   /opt/Zope3/lib/python/Zope/App/Formulator/Fields/IField.pys   IField s   	N(   s	   Interfaces   IField(   s	   Interfaces   IField(    (    s:   /opt/Zope3/lib/python/Zope/App/Formulator/Fields/IField.pys   ?	 s   

=== Added File Zope3/lib/python/Zope/App/Formulator/Fields/IPropertyField.py ===
##############################################################################
#
# Copyright (c) 2001 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
# 
##############################################################################
"""

Revision information: $Id: IPropertyField.py,v 1.1.2.1 2002/01/25 14:11:06 srichter Exp $
"""


from IField import IField


class IPropertyField(IField):
    """
    """

    def setPropertyInContext(value):
        """ """


    def getPropertyInContext():
        """ """


=== Added File Zope3/lib/python/Zope/App/Formulator/Fields/IPropertyField.pyc ===
-í
4^Q<c       s9     d  Z    d k l Z  d e f d „  ƒ  YZ d S(   s   

Revision information: $Id: IPropertyField.pyc,v 1.1.2.1 2002/01/25 14:11:06 srichter Exp $
(   s   IFields   IPropertyFieldc      s&    d  Z    d „  Z  d „  Z RS(   s   
    c    s
     d S(   s    N(    (   s   value(    (    sB   /opt/Zope3/lib/python/Zope/App/Formulator/Fields/IPropertyField.pys   setPropertyInContext s   c      s
     d S(   s    N(    (    (    (    sB   /opt/Zope3/lib/python/Zope/App/Formulator/Fields/IPropertyField.pys   getPropertyInContext s   (   s   __doc__s   setPropertyInContexts   getPropertyInContext(    (    (    sB   /opt/Zope3/lib/python/Zope/App/Formulator/Fields/IPropertyField.pys   IPropertyField s   	N(   s   __doc__s   IFields   IPropertyField(   s   IFields   IPropertyField(    (    sB   /opt/Zope3/lib/python/Zope/App/Formulator/Fields/IPropertyField.pys   ? s   

=== Added File Zope3/lib/python/Zope/App/Formulator/Fields/PropertyField.py ===
##############################################################################
#
# Copyright (c) 2001 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
# 
##############################################################################
"""

Revision information: $Id: PropertyField.py,v 1.1.2.1 2002/01/25 14:11:06 srichter Exp $
"""

from IPropertyField import IPropertyField
from Zope.App.Formulator.Errors import ValidationError


class PropertyField:
    """ """

    __implements__ = IPropertyField


    def setPropertyInContext(self, value):
        """ """
        method = getattr(self.getContext(), 'set'+self.id[0].capitalize()+self.id[1:], None)
        apply(method, (value,))


    def getPropertyInContext(self):
        """ """
        method = getattr(self.getContext(), 'get'+self.id[0].capitalize()+self.id[1:], None)
        return apply(method, ())



=== Added File Zope3/lib/python/Zope/App/Formulator/Fields/PropertyField.pyc ===
-í
]pQ<c       sF     d  Z    d k l Z  d k l Z  d f  d „  ƒ  YZ d S(   s   

Revision information: $Id: PropertyField.pyc,v 1.1.2.1 2002/01/25 14:11:06 srichter Exp $
(   s   IPropertyField(   s   ValidationErrors
   PropertyFieldc      s/    d  Z    e Z  d „  Z " d „  Z RS(   s    c    sT      t  |  i ƒ  d |  i d i ƒ  |  i d t ƒ }  t | | f ƒ d S(   s    s   seti    i   N(	   s   getattrs   selfs
   getContexts   ids
   capitalizes   Nones   methods   applys   value(   s   selfs   values   method(    (    sA   /opt/Zope3/lib/python/Zope/App/Formulator/Fields/PropertyField.pys   setPropertyInContext s   7c    sQ   " # $ t  |  i ƒ  d |  i d i ƒ  |  i d t ƒ } % t | f  ƒ Sd S(   s    s   geti    i   N(   s   getattrs   selfs
   getContexts   ids
   capitalizes   Nones   methods   apply(   s   selfs   method(    (    sA   /opt/Zope3/lib/python/Zope/App/Formulator/Fields/PropertyField.pys   getPropertyInContext" s   7(   s   __doc__s   IPropertyFields   __implements__s   setPropertyInContexts   getPropertyInContext(    (    (    sA   /opt/Zope3/lib/python/Zope/App/Formulator/Fields/PropertyField.pys
   PropertyField s   		N(   s   __doc__s   IPropertyFields   Zope.App.Formulator.Errorss   ValidationErrors
   PropertyField(   s
   PropertyFields   IPropertyFields   ValidationError(    (    sA   /opt/Zope3/lib/python/Zope/App/Formulator/Fields/PropertyField.pys   ? s   

=== Added File Zope3/lib/python/Zope/App/Formulator/Fields/__init__.py ===
##############################################################################
#
# Copyright (c) 2001 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
# 
##############################################################################
"""

Revision information: $Id: __init__.py,v 1.1.2.1 2002/01/25 14:11:06 srichter Exp $
"""


=== Added File Zope3/lib/python/Zope/App/Formulator/Fields/__init__.pyc ===
-í
…^Q<c       s     d  Z   d S(   s   

Revision information: $Id: __init__.pyc,v 1.1.2.1 2002/01/25 14:11:06 srichter Exp $
N(   s   __doc__(    (    (    s<   /opt/Zope3/lib/python/Zope/App/Formulator/Fields/__init__.pys   ? s