[Zope3-checkins] CVS: Zope3/src/zope/app/browser/form - enumerated.py:1.1 configure.zcml:1.25 widget.py:1.61

Philipp von Weitershausen philikon at philikon.de
Fri Jan 16 08:38:49 EST 2004


Update of /cvs-repository/Zope3/src/zope/app/browser/form
In directory cvs.zope.org:/tmp/cvs-serv28581/app/browser/form

Modified Files:
	configure.zcml widget.py 
Added Files:
	enumerated.py 
Log Message:
Changes to the schema package and the widget machinery (see
http://mail.zope.org/pipermail/zope3-dev/2004-January/009265.html):

- Widgets requiring key_type and/or value_type arguments will now check
  whether they implement IField. Before, anything was accepted although
  a field instance was implied. A key_type/value_type of None implies no
  validation of the key/value.

- Basic fields like TextLine, Int, Float, Date, and Datetime are not
  enumerated fields anymore. There are separate Enumerated* fields for
  that purpose now. Extra widgets for that functionality were added
  and configured.


=== Added File Zope3/src/zope/app/browser/form/enumerated.py ===
##############################################################################
#
# Copyright (c) 2004 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.
#
##############################################################################
"""Widgets for enumerated field flavours.

$Id: enumerated.py,v 1.1 2004/01/16 13:38:18 philikon Exp $
"""

from widget import TextWidget, IntWidget, FloatWidget, \
     DatetimeWidget, DateWidget

__metaclass__ = type

class Enumerated:
    """Mixin for enumerated field widgets
    """
    def __init__(self, *args):
        super(Enumerated, self).__init__(*args)
        field = self.context
        if field.allowed_values is not None:
            values = []
            # if field is optional and missing_value isn't in
            # allowed_values, add an additional option at top to represent
            # field.missing_value
            if not field.required and \
                field.missing_value not in field.allowed_values:
                values.append(field.missing_value)
            values += list(field.allowed_values)
            self.__values = values

    def __call__(self):
        selected = self._showData()
        result = ['<select id="%s" name="%s">' % (self.name, self.name)]
        for value in self.__values:
            unconverted = self._unconvert(value)
            selectedStr = unconverted == selected and ' selected' or ''
            result.append('<option value="%s"%s>%s</option>' % \
                   (unconverted, selectedStr, unconverted))
        result.append('</select>')
        return '\n\t'.join(result)

class EnumeratedTextWidget(Enumerated, TextWidget):
    """EnumeratedText widget (for TextLines)
    """

class EnumeratedIntWidget(Enumerated, IntWidget):
    """EnumeratedInt widget
    """

class EnumeratedFloatWidget(Enumerated, FloatWidget):
    """EnumeratedFloat widget
    """

class EnumeratedDatetimeWidget(Enumerated, DatetimeWidget):
    """EnumeratedDatetime widget
    """

class EnumeratedDateWidget(Enumerated, DateWidget):
    """EnumeratedDate widget
    """


=== Zope3/src/zope/app/browser/form/configure.zcml 1.24 => 1.25 ===
--- Zope3/src/zope/app/browser/form/configure.zcml:1.24	Wed Dec 17 05:20:47 2003
+++ Zope3/src/zope/app/browser/form/configure.zcml	Fri Jan 16 08:38:18 2004
@@ -137,6 +137,48 @@
       class="zope.app.browser.form.widget.PasswordWidget"
       />
 
+  <!-- Widgets for enumerated field flavours -->
+
+  <browser:page
+      permission="zope.Public"
+      allowed_interface="zope.app.interfaces.browser.form.IBrowserWidget"
+      for="zope.schema.interfaces.IEnumeratedTextLine"
+      name="edit"
+      class=".enumerated.EnumeratedTextWidget"
+      />  
+
+  <browser:page
+      permission="zope.Public"
+      allowed_interface="zope.app.interfaces.browser.form.IBrowserWidget"
+      for="zope.schema.interfaces.IEnumeratedInt"
+      name="edit"
+      class=".enumerated.EnumeratedIntWidget"
+      />  
+
+  <browser:page
+      permission="zope.Public"
+      allowed_interface="zope.app.interfaces.browser.form.IBrowserWidget"
+      for="zope.schema.interfaces.IEnumeratedFloat"
+      name="edit"
+      class=".enumerated.EnumeratedFloatWidget"
+      />
+
+  <browser:page
+      permission="zope.Public"
+      allowed_interface="zope.app.interfaces.browser.form.IBrowserWidget"
+      for="zope.schema.interfaces.IEnumeratedDatetime"
+      name="edit"
+      class=".enumerated.EnumeratedDatetimeWidget"
+      />  
+
+  <browser:page
+      permission="zope.Public"
+      allowed_interface="zope.app.interfaces.browser.form.IBrowserWidget"
+      for="zope.schema.interfaces.IEnumeratedDate"
+      name="edit"
+      class=".enumerated.EnumeratedDateWidget"
+      />  
+
   <!-- Vocabulary fields share special widget factories that redirect
        to the vocabularies they reference. -->
 


=== Zope3/src/zope/app/browser/form/widget.py 1.60 => 1.61 ===
--- Zope3/src/zope/app/browser/form/widget.py:1.60	Mon Jan 12 17:00:20 2004
+++ Zope3/src/zope/app/browser/form/widget.py	Fri Jan 16 08:38:18 2004
@@ -1,6 +1,6 @@
 ##############################################################################
 #
-# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# Copyright (c) 2001-2004 Zope Corporation and Contributors.
 # All Rights Reserved.
 #
 # This software is subject to the provisions of the Zope Public License,
@@ -537,34 +537,8 @@
 
     def __init__(self, *args):
         super(TextWidget, self).__init__(*args)
-        field = self.context
-        if field.allowed_values is not None:
-            values = []
-            # if field is optional and missing_value isn't in
-            # allowed_values, add an additional option at top to represent
-            # field.missing_value
-            if not field.required and \
-                field.missing_value not in field.allowed_values:
-                values.append(field.missing_value)
-            values += list(field.allowed_values)
-            self.__values = values
-
-    def _select(self):
-        selected = self._showData()
-        result = ['<select id="%s" name="%s">' % (self.name, self.name)]
-        for value in self.__values:
-            unconverted = self._unconvert(value)
-            selectedStr = unconverted == selected and ' selected' or ''
-            result.append('<option value="%s"%s>%s</option>' % \
-                   (unconverted, selectedStr, unconverted))
-        result.append('</select>')
-        return '\n\t'.join(result)
-
 
     def __call__(self):
-        if self.__values:
-            return self._select()
-
         displayMaxWidth = self.getValue('displayMaxWidth') or 0
         if displayMaxWidth > 0:
             return renderElement(self.getValue('tag'),
@@ -614,8 +588,8 @@
     True
     >>> widget.getInputValue()
     'Bob'
-
     """
+
 class ASCII(Bytes):
     """ ASCII
     """
@@ -638,7 +612,6 @@
             except ValueError, v:
                 raise ConversionError("Invalid integer data", v)
 
-
 class FloatWidget(TextWidget):
     displayWidth = 10
 
@@ -651,7 +624,6 @@
             except ValueError, v:
                 raise ConversionError("Invalid floating point data", v)
 
-
 class DatetimeWidget(TextWidget):
     """Datetime entry widget."""
     displayWidth = 20
@@ -665,9 +637,9 @@
             except (DateTimeError, ValueError, IndexError), v:
                 raise ConversionError("Invalid datetime data", v)
 
-
 class DateWidget(TextWidget):
-    "Date entry widget."
+    """Date entry widget.
+    """
     displayWidth = 20
 
     def _convert(self, value):
@@ -678,7 +650,6 @@
                 return parseDatetimetz(value).date()
             except (DateTimeError, ValueError, IndexError), v:
                 raise ConversionError("Invalid datetime data", v)
-
 
 class TextAreaWidget(BrowserWidget):
     """TextArea widget.




More information about the Zope3-Checkins mailing list