Index: /main/waeup.kofa/trunk/src/waeup/kofa/widgets/datewidget.py
===================================================================
--- /main/waeup.kofa/trunk/src/waeup/kofa/widgets/datewidget.py	(revision 8146)
+++ /main/waeup.kofa/trunk/src/waeup/kofa/widgets/datewidget.py	(revision 8147)
@@ -20,55 +20,8 @@
 """
 from datetime import datetime
-from zope.formlib.i18n import _
 from zope.formlib.interfaces import ConversionError, IDisplayWidget
-from zope.formlib.textwidgets import (
-    DateWidget, DateDisplayWidget, escape, DatetimeDisplayWidget)
+from zope.formlib.textwidgets import DateWidget, DateDisplayWidget, escape
 from zope.formlib.widget import renderElement, CustomWidgetFactory
 from zope.interface import implements
-
-class FormattedDateWidget(DateWidget):
-    """A date widget that supports different (and _explicit_) date formats.
-
-    This is an input widget.
-    """
-    date_format = '%Y-%m-%d'
-
-    def _toFieldValue(self, input):
-        if input == self._missing:
-            return self.context.missing_value
-        else:
-            try:
-                # In import files we can use the hash symbol at the end of a
-                # date string to avoid annoying automatic date transformation
-                # by Excel or Calc
-                input = input.strip('#') 
-                value = datetime.strptime(input, self.date_format)
-            except (ValueError, IndexError), v:
-                raise ConversionError("Invalid datetime data", v)
-        return value.date()
-
-    def _toFormValue(self, value):
-        if value:
-            value = value.strftime(self.date_format)
-        return value
-
-class FormattedDateDisplayWidget(DateDisplayWidget):
-    """A date widget that supports different (and _explicit_) date formats.
-
-    This is a display widget.
-    """
-    date_format = '%Y-%m-%d'
-    implements(IDisplayWidget)
-    
-    def __call__(self):
-        if self._renderedValueSet():
-            content = self._data
-        else:
-            content = self.context.default
-        if content == self.context.missing_value:
-            return ""
-        content = content.strftime(self.date_format)
-        return renderElement("span", contents=escape(content),
-                             cssClass=self.cssClass)
 
 #: A dictionary of supported date formats.
@@ -99,5 +52,5 @@
 #: ``us-year``
 #:    middle endian format common in the U.S.: ``MM/DD/YYYY``
-#:    
+#:
 #: For date display widgets there is naturally no difference between a
 #: year and non-year setting (you can for instance use 'le' or 'le-year'
@@ -113,9 +66,84 @@
     'us-year':  ('datepicker-us-year', '%m/%d/%Y'),
     }
+
+#: a dict containing tuples (<FORMAT>, <SHOW_YEAR>) as keys and
+#: suitable CSS tags as values.
+FORMATS_BY_VALUE = dict(
+    [((val[1], 'year' in key), val[0]) for key, val in DATE_FORMATS.items()])
+
+class FormattedDateWidget(DateWidget):
+    """A date widget that supports different (and _explicit_) date formats.
+
+    If the widget is bound to a schema field with respective
+    attributes, it reads its `show_year` and `date_format` attributes
+    (see waeup.kofa.schema.FormattedDate for an example) and sets a
+    CSS tag according to these values.
+
+    The widget also accepts ISO format as a fallback, even if a
+    different format was set. This should help with imports.
+
+    This is an input widget.
+    """
+    date_format = '%Y-%m-%d'
+    show_year = False
+
+    def __init__(self, context, request, *args, **kw):
+        # try to grab date_format and show_year from bound schema field.
+        self.date_format = getattr(context, 'date_format', self.date_format)
+        self.show_year = getattr(context, 'show_year', self.show_year)
+        self.cssClass = FORMATS_BY_VALUE.get((
+            self.date_format, self.show_year), self.cssClass)
+        return super(FormattedDateWidget, self).__init__(
+            context, request, *args, **kw)
+
+    def _toFieldValue(self, input):
+        # In import files we can use the hash symbol at the end of a
+        # date string to avoid annoying automatic date transformation
+        # by Excel or Calc
+        input = input.strip('#')
+        if input == self._missing:
+            return self.context.missing_value
+        else:
+            try:
+                value = datetime.strptime(input, self.date_format)
+            except (ValueError, IndexError), v:
+                try:
+                    # Try ISO format as fallback.
+                    # This is needed for instance during imports.
+                    value = datetime.strptime(
+                        input, FormattedDateWidget.date_format)
+                except (ValueError, IndexError), v:
+                    raise ConversionError("Invalid datetime data", v)
+        return value.date()
+
+    def _toFormValue(self, value):
+        if value:
+            value = value.strftime(self.date_format)
+        return value
+
+class FormattedDateDisplayWidget(DateDisplayWidget):
+    """A date widget that supports different (and _explicit_) date formats.
+
+    This is a display widget.
+    """
+    date_format = '%Y-%m-%d'
+    implements(IDisplayWidget)
+
+    def __call__(self):
+        if self._renderedValueSet():
+            content = self._data
+        else:
+            content = self.context.default
+        if content == self.context.missing_value:
+            return ""
+        content = content.strftime(self.date_format)
+        return renderElement("span", contents=escape(content),
+                             cssClass=self.cssClass)
+
 def FriendlyDateWidget(format):
     """Get a friendly date input widget for `format`.
 
     This widget is suitable for edit and add forms.
-    
+
     Valid `format` values are the keys of `DATE_FORMATS`
     dict. Default is ``le`` (little endian; DD/MM/YYYY).
@@ -134,10 +162,10 @@
 
     This widget is suitable for display forms.
-    
+
     Valid `format` values are the keys of `DATE_FORMATS`
     dict. Default is ``le`` (little endian; DD/MM/YYYY).
 
     This widget is not rendered with a specialized CSS tag for
-    enabling JavaScript datepickers. `css_class` is ignored which means 
+    enabling JavaScript datepickers. `css_class` is ignored which means
     there is nor difference between e.g. ``le`` and ``le-year``.`
     """
@@ -157,5 +185,5 @@
     This widget is not rendered with a specialized CSS tag for
     enabling JavaScript datepickers. `css_class` is ignored which means
-    there is nor difference between e.g. ``le`` and ``le-year``.`
+    there is no difference between e.g. ``le`` and ``le-year``.`
     """
     css_class, date_format = DATE_FORMATS.get(format, DATE_FORMATS['le'])
Index: /main/waeup.kofa/trunk/src/waeup/kofa/widgets/tests/test_datewidget.py
===================================================================
--- /main/waeup.kofa/trunk/src/waeup/kofa/widgets/tests/test_datewidget.py	(revision 8146)
+++ /main/waeup.kofa/trunk/src/waeup/kofa/widgets/tests/test_datewidget.py	(revision 8147)
@@ -55,4 +55,11 @@
             ('type="text"', 'id="field.foo"', 'name="field.foo"',
                 'value="26/03/04"'))
+
+    def testProperties(self):
+        self.assertEqual(self._widget.tag, 'input')
+        self.assertEqual(self._widget.type, 'text')
+        # By default the date format is ISO and the rendered CSS 'datepicker'
+        self.assertEqual(self._widget.cssClass, 'datepicker')
+        self.assertEqual(self._widget.extra, '')
 
     def test_hasInput(self):
