[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/Formulator/Widgets/Browser - BrowserWidget.py:1.1.2.3 DateTimeWidget.py:1.1.2.3 FileWidget.py:1.1.2.3 TextAreaWidget.py:1.1.2.3
Stephan Richter
srichter@cbu.edu
Wed, 27 Mar 2002 09:24:09 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/App/Formulator/Widgets/Browser
In directory cvs.zope.org:/tmp/cvs-serv9605/Widgets/Browser
Modified Files:
Tag: Zope-3x-branch
BrowserWidget.py DateTimeWidget.py FileWidget.py
TextAreaWidget.py
Log Message:
Major changes in Formulator (for details see
srichter-OFS_Formulator-branch checkins):
- Created simple registries for validators, fields and so on.
- Made Formulator compatible with new Publisher code
- Adjusted for better usibility.
Note: More to come as Formulaot is bring developed.
=== Zope3/lib/python/Zope/App/Formulator/Widgets/Browser/BrowserWidget.py 1.1.2.2 => 1.1.2.3 ===
from IBrowserWidget import IBrowserWidget
-from Zope.App.Formulator.Widgets.Widget import Widget
+from Zope.App.Formulator.Widget import Widget
+from Zope.App.Formulator.IPropertyFieldAdapter import IPropertyFieldAdapter
+from Zope.ComponentArchitecture import getAdapter
class BrowserWidget(Widget):
@@ -50,7 +52,8 @@
if REQUEST and REQUEST.has_key('field_'+field.id):
return REQUEST['field_'+field.id]
else:
- return self.getContext().getPropertyInContext()
+ return getAdapter(field, IPropertyFieldAdapter).\
+ getPropertyInContext()
def render(self, REQUEST=None):
=== Zope3/lib/python/Zope/App/Formulator/Widgets/Browser/DateTimeWidget.py 1.1.2.2 => 1.1.2.3 ===
#
-# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
+# 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.
@@ -15,73 +16,33 @@
$Id$
"""
+from Zope.PageTemplate.PageTemplateFile import PageTemplateFile
from Widget import Widget
from DateTime import DateTime
+class DateTimeWidget(CompositeWidget):
-class DateTimeWidget(Widget):
- property_names = Widget.property_names +\
- ['defaultNow', 'dateSeparator', 'timeSeparator',
- 'inputStyle', 'inputOrder',
- 'dateOnly']
+
+ __implements__ = CompositeWidget.__implements__
+
+
+ propertyNames = Widget.property_names +\
+ ['dateSeparator', 'timeSeparator',
+ 'inputStyle', 'inputOrder', 'dateOnly']
+
+ template = PageTemplateFile('datetime.pt')
+
+ widgets = {'year': IntegerWidget(start=0, end=6000),
+ 'month': IntegerWidget(start=0, end=12),
+ 'day': IntegerWidget(start=0, end=31),
+ 'hour': IntegerWidget(start=0, end=23),
+ 'minute': IntegerWidget(start=0, end=59)}
default = None
defaultNow = 0
dateSeparator = '/'
timeSeparator = ':'
inputStyle = "text"
- inputOrder = "ymd"
+ inputOrder = ('year', 'month', 'day')
dateOnly = 0
-
- # FIXME: do we want to handle 'extra'?
-
- def render(self, REQUEST=None):
- # FIXME: backwards compatibility hack:
- if not hasattr(field, 'sub_form'):
- from StandardFields import create_datetime_text_sub_form
- field.sub_form = create_datetime_text_sub_form()
-
- if value is None and field.get_value('default_now'):
- value = DateTime()
-
- if value is None:
- year = None
- month = None
- day = None
- hour = None
- minute = None
- else:
- year = "%04d" % value.year()
- month = "%02d" % value.month()
- day = "%02d" % value.day()
- hour = "%02d" % value.hour()
- minute = "%02d" % value.minute()
-
- input_order = field.get_value('input_order')
- if input_order == 'ymd':
- order = [('year', year),
- ('month', month),
- ('day', day)]
- elif input_order == 'dmy':
- order = [('day', day),
- ('month', month),
- ('year', year)]
- elif input_order == 'mdy':
- order = [('month', month),
- ('day', day),
- ('year', year)]
- result = []
- for sub_field_name, sub_field_value in order:
- result.append(field.render_sub_field(sub_field_name,
- sub_field_value, REQUEST))
- date_result = string.join(result, field.get_value('date_separator'))
- if not field.get_value('date_only'):
- time_result = (field.render_sub_field('hour', hour, REQUEST) +
- field.get_value('time_separator') +
- field.render_sub_field('minute', minute, REQUEST))
- return date_result + ' ' + time_result
- else:
- return date_result
-
-DateTimeWidgetInstance = DateTimeWidget()
=== Zope3/lib/python/Zope/App/Formulator/Widgets/Browser/FileWidget.py 1.1.2.2 => 1.1.2.3 ===
from TextWidget import TextWidget
+from Zope.App.Formulator.Widgets.Browser.BrowserWidget import renderElement
class FileWidget(TextWidget):
@@ -23,3 +24,24 @@
__implements__ = TextWidget.__implements__
type = 'file'
+
+
+ def render(self, REQUEST=None):
+ """Renders this widget as HTML using property values in field.
+ """
+ displayMaxWidth = self.getValue('displayMaxWidth') or 0
+ if displayMaxWidth > 0:
+ return renderElement(self.getValue('tag'),
+ type = self.getValue('type'),
+ name = self.getContext().id,
+ cssClass = self.getValue('cssClass'),
+ size = self.getValue('displayWidth'),
+ maxlength = displayMaxWidth,
+ extra = self.getValue('extra'))
+ else:
+ return renderElement(self.getValue('tag'),
+ type = self.getValue('type'),
+ name = self.getContext().id,
+ cssClass = self.getValue('cssClass'),
+ size = self.getValue('displayWidth'),
+ extra = self.getValue('extra'))
=== Zope3/lib/python/Zope/App/Formulator/Widgets/Browser/TextAreaWidget.py 1.1.2.2 => 1.1.2.3 ===
default = ""
- width = 30
- height = 6
+ width = 80
+ height = 15
extra=""
def render(self, REQUEST=None):