[Zope3-checkins] CVS: Zope3/src/zope/app/browser/form -
vocabularywidget.zcml:1.1.2.1 add.pt:1.22.14.1
add.py:1.38.2.1 addwizard.py:1.12.22.1
configure.zcml:1.25.14.1 display.pt:1.1.68.1
edit.pt:1.15.18.1 editview.py:1.47.4.1 editwizard.pt:1.3.40.1
editwizard.py:1.20.4.1 schemadisplay.py:1.14.4.1
subedit.pt:1.4.78.1 vocabularywidget.py:1.63.14.1
widget.py:1.64.14.1
Garrett Smith
garrett at mojave-corp.com
Thu Feb 26 00:11:20 EST 2004
Update of /cvs-repository/Zope3/src/zope/app/browser/form
In directory cvs.zope.org:/tmp/cvs-serv25181/src/zope/app/browser/form
Modified Files:
Tag: garrett-widgets2-branch
add.pt add.py addwizard.py configure.zcml display.pt edit.pt
editview.py editwizard.pt editwizard.py schemadisplay.py
subedit.pt vocabularywidget.py widget.py
Added Files:
Tag: garrett-widgets2-branch
vocabularywidget.zcml
Log Message:
Yet another branch for widgets refactoring (YABFWR).
=== Added File Zope3/src/zope/app/browser/form/vocabularywidget.zcml ===
<configure xmlns="http://namespaces.zope.org/zope">
<!-- Vocabulary widgets -->
<view
type="zope.publisher.interfaces.browser.IBrowserRequest"
for="zope.schema.interfaces.IVocabulary"
provides=".vocabularywidget.IVocabularyDisplayWidget"
factory=".vocabularywidget.VocabularyDisplayWidget"
permission="zope.Public"
/>
<view
type="zope.publisher.interfaces.browser.IBrowserRequest"
for="zope.schema.interfaces.IVocabulary"
provides=".vocabularywidget.IVocabularyEditWidget"
factory=".vocabularywidget.VocabularyEditWidget"
permission="zope.Public"
/>
<view
type="zope.publisher.interfaces.browser.IBrowserRequest"
for="zope.schema.interfaces.IVocabulary"
provides=".vocabularywidget.IVocabularyListDisplayWidget"
factory=".vocabularywidget.VocabularyListDisplayWidget"
permission="zope.Public"
/>
<view
type="zope.publisher.interfaces.browser.IBrowserRequest"
for="zope.schema.interfaces.IVocabulary"
provides=".vocabularywidget.IVocabularyMultiEditWidget"
factory=".vocabularywidget.VocabularyMultiEditWidget"
permission="zope.Public"
/>
<view
type="zope.publisher.interfaces.browser.IBrowserRequest"
for="zope.schema.interfaces.IVocabulary"
provides=".vocabularywidget.IVocabularyBagDisplayWidget"
factory=".vocabularywidget.VocabularyBagDisplayWidget"
permission="zope.Public"
/>
<!-- Iterable Query Helper Views -->
<view
type="zope.publisher.interfaces.browser.IBrowserRequest"
for="zope.schema.interfaces.IIterableVocabularyQuery"
provides=".vocabularywidget.IWidgetQueryHelper"
factory=".vocabularywidget.IterableVocabularyQueryView"
permission="zope.Public"
/>
<view
type="zope.publisher.interfaces.browser.IBrowserRequest"
for="zope.schema.interfaces.IIterableVocabularyQuery"
provides=".vocabularywidget.IWidgetQueryListHelper"
factory=".vocabularywidget.IterableVocabularyQueryMultiView"
permission="zope.Public"
/>
</configure>
=== Zope3/src/zope/app/browser/form/add.pt 1.22 => 1.22.14.1 ===
--- Zope3/src/zope/app/browser/form/add.pt:1.22 Tue Feb 3 17:07:07 2004
+++ Zope3/src/zope/app/browser/form/add.pt Thu Feb 26 00:10:49 2004
@@ -30,19 +30,29 @@
<div class="label">Extra top</div>
<div class="label"><input type="text" style="width:100%" /></div>
</div>
- <div class="row"
- metal:define-macro="widget_rows" tal:repeat="widget view/widgets"
- tal:content="structure widget/row">
- <div class="label">Name</div>
- <div class="field"><input type="text" style="width:100%"/></div>
- </div>
+
+ <div class="row"
+ metal:define-macro="widget_rows" tal:repeat="widget view/widgets">
+ <div class="label" tal:content="structure widget/label">Name</div>
+ <div class="field" tal:content="structure widget">
+ <input type="text" style="width:100%"/>
+ </div>
+ <div class="error" tal:define="error widget/error"
+ tal:condition="error" tal:content="structure error">
+ The Error
+ </div>
+ </div>
+
<div class="separator"></div>
+
<div class="row"
metal:define-slot="extra_bottom" tal:replace="nothing">
<div class="label">Extra bottom</div>
<div class="field"><input type="text" style="width:100%" /></div>
</div>
+
<div class="separator"></div>
+
</div>
<br/><br/>
<div class="row">
=== Zope3/src/zope/app/browser/form/add.py 1.38 => 1.38.2.1 ===
--- Zope3/src/zope/app/browser/form/add.py:1.38 Wed Feb 25 18:02:17 2004
+++ Zope3/src/zope/app/browser/form/add.py Thu Feb 26 00:10:49 2004
@@ -24,6 +24,7 @@
from zope.app.event.objectevent import ObjectCreatedEvent
from zope.app.form.utility import setUpWidgets, getWidgetsData
from zope.app.i18n import ZopeMessageIDFactory as _
+from zope.app.interfaces.form import IEditWidget
from zope.app.interfaces.form import WidgetsError
from zope.app.pagetemplate.simpleviewclass import SimpleViewClass
from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
@@ -42,7 +43,7 @@
"""
def _setUpWidgets(self):
- setUpWidgets(self, self.schema, names=self.fieldNames)
+ setUpWidgets(self, self.schema, IEditWidget, names=self.fieldNames)
def update(self):
@@ -54,10 +55,7 @@
self.update_status = ''
try:
- data = getWidgetsData(self, self.schema,
- strict=True,
- names=self.fieldNames,
- set_missing=False)
+ data = getWidgetsData(self, self.schema, names=self.fieldNames)
self.createAndAdd(data)
except WidgetsError, errors:
self.errors = errors
=== Zope3/src/zope/app/browser/form/addwizard.py 1.12 => 1.12.22.1 ===
--- Zope3/src/zope/app/browser/form/addwizard.py:1.12 Fri Nov 21 12:10:10 2003
+++ Zope3/src/zope/app/browser/form/addwizard.py Thu Feb 26 00:10:49 2004
@@ -22,6 +22,7 @@
from zope.app.event.objectevent import ObjectCreatedEvent
from zope.app.form.utility import setUpWidgets
from zope.app.interfaces.form import WidgetsError
+from zope.app.interfaces.form import IEditWidget
from zope.app.pagetemplate.simpleviewclass import SimpleViewClass
from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
from zope.component import getAdapter
@@ -44,7 +45,7 @@
else:
self.storage = WizardStorage(self.fieldNames, None)
- setUpWidgets(self, self.schema, names=self.fieldNames)
+ setUpWidgets(self, self.schema, IEditWidget, names=self.fieldNames)
def create(self, *args, **kw):
"""Do the actual instantiation."""
=== Zope3/src/zope/app/browser/form/configure.zcml 1.25 => 1.25.14.1 ===
--- Zope3/src/zope/app/browser/form/configure.zcml:1.25 Fri Jan 16 08:38:18 2004
+++ Zope3/src/zope/app/browser/form/configure.zcml Thu Feb 26 00:10:49 2004
@@ -1,366 +1,266 @@
-<configure
- xmlns="http://namespaces.zope.org/zope"
- xmlns:browser="http://namespaces.zope.org/browser">
+<configure xmlns="http://namespaces.zope.org/zope">
+
+ <!-- Core display widgets -->
- <!-- Form Widget View Directives -->
- <browser:defaultView for="zope.schema.interfaces.IField" name="edit" />
-
- <!-- XXX The next directive should be replaced by one that
- uses a 'smart' widget that knows how to deal with type-agnostic
- values, which is the porpose of zope.schema.Field -->
-
- <browser:page
- permission="zope.Public"
- allowed_interface="zope.app.interfaces.browser.form.IBrowserWidget"
+ <view
+ type="zope.publisher.interfaces.browser.IBrowserRequest"
for="zope.schema.interfaces.IField"
- name="edit"
- class="zope.app.browser.form.widget.BrowserWidget"
- />
-
- <browser:page
+ provides="zope.app.interfaces.form.IDisplayWidget"
+ factory="zope.app.browser.form.widget.DisplayWidget"
permission="zope.Public"
- allowed_interface="zope.app.interfaces.browser.form.IBrowserWidget"
- for="zope.schema.interfaces.ITextLine"
- name="edit"
- class="zope.app.browser.form.widget.TextWidget"
/>
-
- <browser:page
+
+ <!-- Core edit widgets -->
+
+ <view
+ type="zope.publisher.interfaces.browser.IBrowserRequest"
+ for="zope.schema.interfaces.ITextLine"
+ provides="zope.app.interfaces.form.IEditWidget"
+ factory="zope.app.browser.form.widget.TextWidget"
permission="zope.Public"
- allowed_interface="zope.app.interfaces.browser.form.IBrowserWidget"
- for="zope.schema.interfaces.IText"
- name="edit"
- class="zope.app.browser.form.widget.TextAreaWidget"
/>
- <browser:page
+ <view
+ type="zope.publisher.interfaces.browser.IBrowserRequest"
+ for="zope.schema.interfaces.IText"
+ provides="zope.app.interfaces.form.IEditWidget"
+ factory="zope.app.browser.form.widget.TextAreaWidget"
permission="zope.Public"
- allowed_interface="zope.app.interfaces.browser.form.IBrowserWidget"
- for="zope.schema.interfaces.ISourceText"
- name="edit"
- class="zope.app.browser.form.widget.TextAreaWidget"
/>
- <browser:page
+ <view
+ type="zope.publisher.interfaces.browser.IBrowserRequest"
+ for="zope.schema.interfaces.ISourceText"
+ provides="zope.app.interfaces.form.IEditWidget"
+ factory="zope.app.browser.form.widget.TextAreaWidget"
permission="zope.Public"
- allowed_interface="zope.app.interfaces.browser.form.IBrowserWidget"
- for="zope.schema.interfaces.IBytesLine"
- name="edit"
- class="zope.app.browser.form.widget.BytesWidget"
/>
- <browser:page
+ <view
+ type="zope.publisher.interfaces.browser.IBrowserRequest"
+ for="zope.schema.interfaces.IBytesLine"
+ provides="zope.app.interfaces.form.IEditWidget"
+ factory="zope.app.browser.form.widget.BytesWidget"
permission="zope.Public"
- allowed_interface="zope.app.interfaces.browser.form.IBrowserWidget"
- for="zope.schema.interfaces.IBytes"
- name="edit"
- class="zope.app.browser.form.widget.FileWidget"
/>
- <browser:page
+ <view
+ type="zope.publisher.interfaces.browser.IBrowserRequest"
+ for="zope.schema.interfaces.IBytes"
+ provides="zope.app.interfaces.form.IEditWidget"
+ factory="zope.app.browser.form.widget.FileWidget"
permission="zope.Public"
- allowed_interface="zope.app.interfaces.browser.form.IBrowserWidget"
- for="zope.schema.interfaces.IASCII"
- name="edit"
- class="zope.app.browser.form.widget.BytesAreaWidget"
/>
- <browser:page
+ <view
+ type="zope.publisher.interfaces.browser.IBrowserRequest"
+ for="zope.schema.interfaces.IASCII"
+ provides="zope.app.interfaces.form.IEditWidget"
+ factory="zope.app.browser.form.widget.BytesAreaWidget"
permission="zope.Public"
- allowed_interface="zope.app.interfaces.browser.form.IBrowserWidget"
- for="zope.schema.interfaces.IInt"
- name="edit"
- class="zope.app.browser.form.widget.IntWidget"
/>
- <browser:page
+ <view
+ type="zope.publisher.interfaces.browser.IBrowserRequest"
+ for="zope.schema.interfaces.IInt"
+ provides="zope.app.interfaces.form.IEditWidget"
+ factory="zope.app.browser.form.widget.IntWidget"
permission="zope.Public"
- allowed_interface="zope.app.interfaces.browser.form.IBrowserWidget"
- for="zope.schema.interfaces.IFloat"
- name="edit"
- class="zope.app.browser.form.widget.FloatWidget"
/>
- <browser:page
+ <view
+ type="zope.publisher.interfaces.browser.IBrowserRequest"
+ for="zope.schema.interfaces.IFloat"
+ provides="zope.app.interfaces.form.IEditWidget"
+ factory="zope.app.browser.form.widget.FloatWidget"
permission="zope.Public"
- allowed_interface="zope.app.interfaces.browser.form.IBrowserWidget"
- for="zope.schema.interfaces.IDatetime"
- name="edit"
- class="zope.app.browser.form.widget.DatetimeWidget"
/>
- <browser:page
+ <view
+ type="zope.publisher.interfaces.browser.IBrowserRequest"
+ for="zope.schema.interfaces.IDatetime"
+ provides="zope.app.interfaces.form.IEditWidget"
+ factory="zope.app.browser.form.widget.DatetimeWidget"
permission="zope.Public"
- allowed_interface="zope.app.interfaces.browser.form.IBrowserWidget"
- for="zope.schema.interfaces.IDate"
- name="edit"
- class="zope.app.browser.form.widget.DateWidget"
/>
- <browser:page
+ <view
+ type="zope.publisher.interfaces.browser.IBrowserRequest"
+ for="zope.schema.interfaces.IDate"
+ provides="zope.app.interfaces.form.IEditWidget"
+ factory="zope.app.browser.form.widget.DateWidget"
permission="zope.Public"
- allowed_interface="zope.app.interfaces.browser.form.IBrowserWidget"
- for="zope.schema.interfaces.IBool"
- name="edit"
- class="zope.app.browser.form.widget.CheckBoxWidget"
/>
- <browser:page
+ <view
+ type="zope.publisher.interfaces.browser.IBrowserRequest"
+ for="zope.schema.interfaces.IBool"
+ provides="zope.app.interfaces.form.IEditWidget"
+ factory="zope.app.browser.form.widget.CheckBoxWidget"
permission="zope.Public"
- allowed_interface="zope.app.interfaces.browser.form.IBrowserWidget"
- for="zope.schema.interfaces.ITuple"
- name="edit"
- class="zope.app.browser.form.widget.TupleSequenceWidget"
/>
- <browser:page
+ <view
+ type="zope.publisher.interfaces.browser.IBrowserRequest"
+ for="zope.schema.interfaces.ITuple"
+ provides="zope.app.interfaces.form.IEditWidget"
+ factory="zope.app.browser.form.widget.TupleSequenceWidget"
permission="zope.Public"
- allowed_interface="zope.app.interfaces.browser.form.IBrowserWidget"
- for="zope.schema.interfaces.IList"
- name="edit"
- class="zope.app.browser.form.widget.ListSequenceWidget"
/>
- <browser:page
+ <view
+ type="zope.publisher.interfaces.browser.IBrowserRequest"
+ for="zope.schema.interfaces.IList"
+ provides="zope.app.interfaces.form.IEditWidget"
+ factory="zope.app.browser.form.widget.ListSequenceWidget"
permission="zope.Public"
- allowed_interface="zope.app.interfaces.browser.form.IBrowserWidget"
- for="zope.schema.interfaces.IObject"
- name="edit"
- class="zope.app.browser.form.widget.ObjectWidget"
/>
- <browser:page
- permission="zope.Public"
- allowed_interface="zope.app.interfaces.browser.form.IBrowserWidget"
+ <view
+ type="zope.publisher.interfaces.browser.IBrowserRequest"
for="zope.schema.interfaces.IPassword"
- name="edit"
- class="zope.app.browser.form.widget.PasswordWidget"
+ provides="zope.app.interfaces.form.IEditWidget"
+ factory="zope.app.browser.form.widget.PasswordWidget"
+ permission="zope.Public"
/>
<!-- Widgets for enumerated field flavours -->
- <browser:page
- permission="zope.Public"
- allowed_interface="zope.app.interfaces.browser.form.IBrowserWidget"
+ <view
+ type="zope.publisher.interfaces.browser.IBrowserRequest"
for="zope.schema.interfaces.IEnumeratedTextLine"
- name="edit"
- class=".enumerated.EnumeratedTextWidget"
- />
-
- <browser:page
+ provides="zope.app.interfaces.form.IEditWidget"
+ factory=".enumerated.EnumeratedTextWidget"
permission="zope.Public"
- allowed_interface="zope.app.interfaces.browser.form.IBrowserWidget"
- for="zope.schema.interfaces.IEnumeratedInt"
- name="edit"
- class=".enumerated.EnumeratedIntWidget"
- />
+ />
- <browser:page
+ <view
+ type="zope.publisher.interfaces.browser.IBrowserRequest"
+ for="zope.schema.interfaces.IEnumeratedInt"
+ provides="zope.app.interfaces.form.IEditWidget"
+ factory=".enumerated.EnumeratedIntWidget"
permission="zope.Public"
- allowed_interface="zope.app.interfaces.browser.form.IBrowserWidget"
- for="zope.schema.interfaces.IEnumeratedFloat"
- name="edit"
- class=".enumerated.EnumeratedFloatWidget"
/>
- <browser:page
+ <view
+ type="zope.publisher.interfaces.browser.IBrowserRequest"
+ for="zope.schema.interfaces.IEnumeratedFloat"
+ provides="zope.app.interfaces.form.IEditWidget"
+ factory=".enumerated.EnumeratedFloatWidget"
permission="zope.Public"
- allowed_interface="zope.app.interfaces.browser.form.IBrowserWidget"
- for="zope.schema.interfaces.IEnumeratedDatetime"
- name="edit"
- class=".enumerated.EnumeratedDatetimeWidget"
- />
+ />
- <browser:page
+ <view
+ type="zope.publisher.interfaces.browser.IBrowserRequest"
+ for="zope.schema.interfaces.IEnumeratedDatetime"
+ provides="zope.app.interfaces.form.IEditWidget"
+ factory=".enumerated.EnumeratedDatetimeWidget"
permission="zope.Public"
- allowed_interface="zope.app.interfaces.browser.form.IBrowserWidget"
- for="zope.schema.interfaces.IEnumeratedDate"
- name="edit"
- class=".enumerated.EnumeratedDateWidget"
- />
+ />
+ <view
+ type="zope.publisher.interfaces.browser.IBrowserRequest"
+ for="zope.schema.interfaces.IEnumeratedDate"
+ provides="zope.app.interfaces.form.IEditWidget"
+ factory=".enumerated.EnumeratedDateWidget"
+ permission="zope.Public"
+ />
+
<!-- Vocabulary fields share special widget factories that redirect
to the vocabularies they reference. -->
<!-- Single selection -->
+
<view
- permission="zope.Public"
type="zope.publisher.interfaces.browser.IBrowserRequest"
- allowed_interface="zope.app.interfaces.browser.form.IBrowserWidget"
- for="zope.schema.vocabulary.IVocabularyField"
- name="display"
+ for="zope.schema.interfaces.IVocabularyField"
+ provides="zope.app.interfaces.form.IDisplayWidget"
factory=".vocabularywidget.VocabularyFieldDisplayWidget"
+ permission="zope.Public"
/>
<view
- permission="zope.Public"
type="zope.publisher.interfaces.browser.IBrowserRequest"
- allowed_interface="zope.app.interfaces.browser.form.IBrowserWidget"
- for="zope.schema.vocabulary.IVocabularyField"
- name="edit"
+ for="zope.schema.interfaces.IVocabularyField"
+ provides="zope.app.interfaces.form.IEditWidget"
factory=".vocabularywidget.VocabularyFieldEditWidget"
+ permission="zope.Public"
/>
<!-- Bags -->
+
<view
- permission="zope.Public"
type="zope.publisher.interfaces.browser.IBrowserRequest"
- allowed_interface="zope.app.interfaces.browser.form.IBrowserWidget"
- for="zope.schema.vocabulary.IVocabularyBagField"
- name="display"
+ for="zope.schema.interfaces.IVocabularyBagField"
+ provides="zope.app.interfaces.form.IDisplayWidget"
factory=".vocabularywidget.VocabularyBagFieldDisplayWidget"
+ permission="zope.Public"
/>
-
+
<view
- permission="zope.Public"
type="zope.publisher.interfaces.browser.IBrowserRequest"
- allowed_interface="zope.app.interfaces.browser.form.IBrowserWidget"
- for="zope.schema.vocabulary.IVocabularyBagField"
- name="edit"
+ for="zope.schema.interfaces.IVocabularyBagField"
+ provides="zope.app.interfaces.form.IEditWidget"
factory=".vocabularywidget.VocabularyBagFieldEditWidget"
- />
-
- <!-- Lists -->
- <view
permission="zope.Public"
- type="zope.publisher.interfaces.browser.IBrowserRequest"
- allowed_interface="zope.app.interfaces.browser.form.IBrowserWidget"
- for="zope.schema.vocabulary.IVocabularyListField"
- name="display"
- factory=".vocabularywidget.VocabularyListFieldDisplayWidget"
/>
- <view
- permission="zope.Public"
- type="zope.publisher.interfaces.browser.IBrowserRequest"
- allowed_interface="zope.app.interfaces.browser.form.IBrowserWidget"
- for="zope.schema.vocabulary.IVocabularyListField"
- name="edit"
- factory=".vocabularywidget.VocabularyListFieldEditWidget"
- />
+ <!-- Lists -->
- <!-- Sets -->
<view
- permission="zope.Public"
type="zope.publisher.interfaces.browser.IBrowserRequest"
- allowed_interface="zope.app.interfaces.browser.form.IBrowserWidget"
- for="zope.schema.vocabulary.IVocabularySetField"
- name="display"
- factory=".vocabularywidget.VocabularySetFieldDisplayWidget"
- />
-
- <view
+ for="zope.schema.interfaces.IVocabularyListField"
+ provides="zope.app.interfaces.form.IDisplayWidget"
+ factory=".vocabularywidget.VocabularyListFieldDisplayWidget"
permission="zope.Public"
- type="zope.publisher.interfaces.browser.IBrowserRequest"
- allowed_interface="zope.app.interfaces.browser.form.IBrowserWidget"
- for="zope.schema.vocabulary.IVocabularySetField"
- name="edit"
- factory=".vocabularywidget.VocabularySetFieldEditWidget"
/>
- <!-- Unique lists -->
<view
- permission="zope.Public"
type="zope.publisher.interfaces.browser.IBrowserRequest"
- allowed_interface="zope.app.interfaces.browser.form.IBrowserWidget"
- for="zope.schema.vocabulary.IVocabularyUniqueListField"
- name="display"
- factory=".vocabularywidget.VocabularyUniqueListFieldDisplayWidget"
- />
-
- <view
+ for="zope.schema.interfaces.IVocabularyListField"
+ provides="zope.app.interfaces.form.IEditWidget"
+ factory=".vocabularywidget.VocabularyListFieldEditWidget"
permission="zope.Public"
- type="zope.publisher.interfaces.browser.IBrowserRequest"
- allowed_interface="zope.app.interfaces.browser.form.IBrowserWidget"
- for="zope.schema.vocabulary.IVocabularyUniqueListField"
- name="edit"
- factory=".vocabularywidget.VocabularyUniqueListFieldEditWidget"
/>
- <!-- Query view helpers -->
- <view
- permission="zope.Public"
- type="zope.publisher.interfaces.browser.IBrowserRequest"
- allowed_interface="zope.app.interfaces.browser.form.IVocabularyQueryView"
- for="zope.schema.interfaces.IIterableVocabularyQuery"
- name="widget-query-helper"
- factory=".vocabularywidget.IterableVocabularyQueryView"
- />
+ <!-- Sets -->
<view
- permission="zope.Public"
type="zope.publisher.interfaces.browser.IBrowserRequest"
- allowed_interface="zope.app.interfaces.browser.form.IVocabularyQueryView"
- for="zope.schema.interfaces.IIterableVocabularyQuery"
- name="widget-query-list-helper"
- factory=".vocabularywidget.IterableVocabularyQueryMultiView"
- />
-
- <!-- Vocabulary field display widgets -->
- <view
+ for="zope.schema.interfaces.IVocabularySetField"
+ provides="zope.app.interfaces.form.IDisplayWidget"
+ factory=".vocabularywidget.VocabularySetFieldDisplayWidget"
permission="zope.Public"
- type="zope.publisher.interfaces.browser.IBrowserRequest"
- factory=".vocabularywidget.VocabularyDisplayWidget"
- name="field-display-widget"
- for="zope.schema.interfaces.IVocabulary"
/>
-
+
<view
- permission="zope.Public"
type="zope.publisher.interfaces.browser.IBrowserRequest"
- factory=".vocabularywidget.VocabularyBagDisplayWidget"
- name="field-display-bag-widget"
- for="zope.schema.interfaces.IVocabulary"
- />
-
- <view
+ for="zope.schema.interfaces.IVocabularySetField"
+ provides="zope.app.interfaces.form.IEditWidget"
+ factory=".vocabularywidget.VocabularySetFieldEditWidget"
permission="zope.Public"
- type="zope.publisher.interfaces.browser.IBrowserRequest"
- factory=".vocabularywidget.VocabularyListDisplayWidget"
- name="field-display-list-widget"
- for="zope.schema.interfaces.IVocabulary"
/>
- <view
- permission="zope.Public"
- type="zope.publisher.interfaces.browser.IBrowserRequest"
- factory=".vocabularywidget.VocabularyBagDisplayWidget"
- name="field-display-set-widget"
- for="zope.schema.interfaces.IVocabulary"
- />
+ <!-- Unique lists -->
<view
- permission="zope.Public"
type="zope.publisher.interfaces.browser.IBrowserRequest"
- factory=".vocabularywidget.VocabularyListDisplayWidget"
- name="field-display-unique-list-widget"
- for="zope.schema.interfaces.IVocabulary"
- />
-
- <!-- Vocabulary edit widgets -->
- <view
+ for="zope.schema.interfaces.IVocabularyUniqueListField"
+ provides="zope.app.interfaces.form.IDisplayWidget"
+ factory=".vocabularywidget.VocabularyUniqueListFieldDisplayWidget"
permission="zope.Public"
- type="zope.publisher.interfaces.browser.IBrowserRequest"
- factory=".vocabularywidget.VocabularyEditWidget"
- name="field-edit-widget"
- for="zope.schema.interfaces.IVocabulary"
/>
-
+
<view
- permission="zope.Public"
type="zope.publisher.interfaces.browser.IBrowserRequest"
- factory=".vocabularywidget.VocabularyMultiEditWidget"
- name="field-edit-list-widget"
- for="zope.schema.interfaces.IVocabulary"
- />
-
- <!-- Default simple display view -->
- <browser:page
+ for="zope.schema.interfaces.IVocabularyUniqueListField"
+ provides="zope.app.interfaces.form.IEditWidget"
+ factory=".vocabularywidget.VocabularyUniqueListFieldEditWidget"
permission="zope.Public"
- allowed_interface="zope.app.interfaces.browser.form.IBrowserWidget"
- for="zope.schema.interfaces.IField"
- name="display"
- class="zope.app.browser.form.widget.DisplayWidget"
/>
+
+ <!-- implementation support for vocabulary field widgets -->
+
+ <include file="vocabularywidget.zcml" />
</configure>
=== Zope3/src/zope/app/browser/form/display.pt 1.1 => 1.1.68.1 ===
--- Zope3/src/zope/app/browser/form/display.pt:1.1 Wed Apr 16 17:56:03 2003
+++ Zope3/src/zope/app/browser/form/display.pt Thu Feb 26 00:10:49 2004
@@ -18,11 +18,16 @@
<div class="label">Extra top</div>
<div class="field"><input type="text" style="width:100%" /></div>
</div>
- <div class="row"
- metal:define-macro="widget_rows" tal:repeat="widget view/widgets"
- tal:content="structure widget/row">
- <div class="label">Name</div>
- <div class="field"><input type="text" style="width:100%" /></div>
+ <div class="row" metal:define-macro="widget_rows"
+ tal:repeat="widget view/widgets">
+ <div class="label" tal:content="structure widget/label">Name</div>
+ <div class="field" tal:content="structure widget">
+ <input type="text" style="width:100%"/>
+ </div>
+ <div class="error" tal:define="error widget/error"
+ tal:condition="error" tal:content="structure error">
+ The Error
+ </div>
</div>
<div class="row"
metal:define-slot="extra_bottom" tal:replace="nothing">
=== Zope3/src/zope/app/browser/form/edit.pt 1.15 => 1.15.18.1 ===
--- Zope3/src/zope/app/browser/form/edit.pt:1.15 Mon Jan 12 13:56:08 2004
+++ Zope3/src/zope/app/browser/form/edit.pt Thu Feb 26 00:10:49 2004
@@ -32,11 +32,16 @@
<div class="label">Extra top</div>
<div class="field"><input type="text" style="width:100%" /></div>
</div>
- <div class="row"
- metal:define-macro="widget_rows" tal:repeat="widget view/widgets"
- tal:content="structure widget/row">
- <div class="label">Name</div>
- <div class="field"><input type="text" style="width:100%" /></div>
+ <div class="row" metal:define-macro="widget_rows"
+ tal:repeat="widget view/widgets">
+ <div class="label" tal:content="structure widget/label">Name</div>
+ <div class="field" tal:content="structure widget">
+ <input type="text" style="width:100%"/>
+ </div>
+ <div class="error" tal:define="error widget/error"
+ tal:condition="error" tal:content="structure error">
+ The Error
+ </div>
</div>
<div class="separator"></div>
<div class="row"
=== Zope3/src/zope/app/browser/form/editview.py 1.47 => 1.47.4.1 ===
--- Zope3/src/zope/app/browser/form/editview.py:1.47 Wed Feb 25 08:21:50 2004
+++ Zope3/src/zope/app/browser/form/editview.py Thu Feb 26 00:10:49 2004
@@ -65,7 +65,7 @@
adapted.__parent__ = self.context
self.adapted = adapted
setUpEditWidgets(self, self.schema, names=self.fieldNames,
- content=self.adapted)
+ context=self.adapted)
def setPrefix(self, prefix):
for widget in self.widgets():
@@ -93,8 +93,8 @@
if Update in self.request:
changed = False
try:
- changed = applyWidgetsChanges(self, content, self.schema,
- names=self.fieldNames, exclude_readonly=True)
+ changed = applyWidgetsChanges(self, self.schema,
+ names=self.fieldNames, context=content)
# We should not generate events when an adapter is used.
# That's the adapter's job.
if changed and self.context is self.adapted:
@@ -103,8 +103,8 @@
self.errors = errors
status = _("An error occured.")
else:
- setUpEditWidgets(self, self.schema, force=1,
- names=self.fieldNames, content=self.adapted)
+ setUpEditWidgets(self, self.schema, ignoreStickyValues=True,
+ names=self.fieldNames, context=self.adapted)
if changed:
self.changed()
formatter = self.request.locale.dates.getFormatter(
=== Zope3/src/zope/app/browser/form/editwizard.pt 1.3 => 1.3.40.1 ===
--- Zope3/src/zope/app/browser/form/editwizard.pt:1.3 Mon Jul 14 11:28:23 2003
+++ Zope3/src/zope/app/browser/form/editwizard.pt Thu Feb 26 00:10:49 2004
@@ -25,11 +25,16 @@
<div class="label">Extra top</div>
<div class="field"><input type="text" style="width:100%" /></div>
</div>
- <div class="row"
- metal:define-macro="widget_rows" tal:repeat="widget view/widgets"
- tal:content="structure widget/row">
- <div class="label">Name</div>
- <div class="field"><input type="text" style="width:100%" /></div>
+ <div class="row" metal:define-macro="widget_rows"
+ tal:repeat="widget view/widgets">
+ <div class="label" tal:content="structure widget/label">Name</div>
+ <div class="field" tal:content="structure widget">
+ <input type="text" style="width:100%"/>
+ </div>
+ <div class="error" tal:define="error widget/error"
+ tal:condition="error" tal:content="structure error">
+ The Error
+ </div>
</div>
<div tal:replace="structure view/renderHidden">
<!-- type=hidden input controls for passing state without session -->
=== Zope3/src/zope/app/browser/form/editwizard.py 1.20 => 1.20.4.1 ===
--- Zope3/src/zope/app/browser/form/editwizard.py:1.20 Wed Feb 25 08:21:50 2004
+++ Zope3/src/zope/app/browser/form/editwizard.py Thu Feb 26 00:10:49 2004
@@ -72,9 +72,8 @@
self.storage = WizardStorage(self.fieldNames, adapted)
# Add all our widgets as attributes on this view
- setUpEditWidgets(
- self, self.schema, names=self.fieldNames, content=self.storage
- )
+ setUpEditWidgets(self, self.schema, names=self.fieldNames,
+ context=self.storage)
def widgets(self):
return [getattr(self, name+'_widget')
@@ -117,10 +116,7 @@
# Validate the current pane, and set self.errors
try:
names = self.currentPane().names
- data = getWidgetsData(
- self, self.schema, strict=True, set_missing=True,
- names=names, exclude_readonly=True
- )
+ data = getWidgetsData(self, self.schema, names=names)
self.errors = {}
except WidgetsError, errors:
x = {}
@@ -142,10 +138,7 @@
# Data from panes other than the current one is still
# stuck in request
self.storage.update(getWidgetsData(
- self, self.schema, strict=True, set_missing=True,
- names=self.fieldNames, exclude_readonly=True
- ))
-
+ self, self.schema, names=self.fieldNames))
if self.apply_update(self.storage):
self.feedback = _(u'No changes to save')
else:
@@ -179,10 +172,8 @@
for k,v in storage.items():
getattr(self,k).setRenderedValue(v)
content = self.adapted
- changed = applyWidgetsChanges(
- self, content, self.schema,
- names=self.fieldNames, exclude_readonly=True
- )
+ changed = applyWidgetsChanges(self, self.schema,
+ names=self.fieldNames, context=content)
# We should not generate events when an adapter is used.
# That's the adapter's job
if changed and self.context is self.adapted:
=== Zope3/src/zope/app/browser/form/schemadisplay.py 1.14 => 1.14.4.1 ===
--- Zope3/src/zope/app/browser/form/schemadisplay.py:1.14 Wed Feb 25 08:21:50 2004
+++ Zope3/src/zope/app/browser/form/schemadisplay.py Thu Feb 26 00:10:49 2004
@@ -54,7 +54,7 @@
adapted.__parent__ = self.context
self.adapted = adapted
setUpDisplayWidgets(self, self.schema, names=self.fieldNames,
- content=adapted)
+ context=adapted)
def setPrefix(self, prefix):
for widget in self.widgets():
=== Zope3/src/zope/app/browser/form/subedit.pt 1.4 => 1.4.78.1 ===
--- Zope3/src/zope/app/browser/form/subedit.pt:1.4 Fri Feb 21 04:45:21 2003
+++ Zope3/src/zope/app/browser/form/subedit.pt Thu Feb 26 00:10:49 2004
@@ -32,11 +32,16 @@
<div class="label">Extra top</div>
<div class="field"><input type="text" style="width:100%" /></div>
</div>
- <div class="row"
- metal:define-macro="widget_rows" tal:repeat="widget view/widgets"
- tal:content="structure widget/row">
- <div class="label">Name</div>
- <div class="field"><input type="text" style="width:100%" /></div>
+ <div class="row" metal:define-macro="widget_rows"
+ tal:repeat="widget view/widgets">
+ <div class="label" tal:content="structure widget/label">Name</div>
+ <div class="field" tal:content="structure widget">
+ <input type="text" style="width:100%"/>
+ </div>
+ <div class="error" tal:define="error widget/error"
+ tal:condition="error" tal:content="structure error">
+ The Error
+ </div>
</div>
<div class="row"
metal:define-slot="extra_bottom" tal:replace="nothing">
=== Zope3/src/zope/app/browser/form/vocabularywidget.py 1.63 => 1.63.14.1 ===
--- Zope3/src/zope/app/browser/form/vocabularywidget.py:1.63 Thu Feb 5 09:55:46 2004
+++ Zope3/src/zope/app/browser/form/vocabularywidget.py Thu Feb 26 00:10:49 2004
@@ -21,7 +21,7 @@
"""
from xml.sax.saxutils import quoteattr
-from zope.interface import implements, implementedBy
+from zope.interface import Interface, implements, implementedBy
from zope.interface.declarations import directlyProvides
from zope.publisher.browser import BrowserView
from zope.security.proxy import trustedRemoveSecurityProxy
@@ -36,75 +36,84 @@
from zope.app.services.servicenames import Translation
-# These widget factories delegate to the vocabulary on the field.
+# Marker interfaces for vocabulary widget lookup
-# Display
-
-def VocabularyFieldDisplayWidget(field, request):
- """Return a display widget based on a vocabulary field."""
- return _get_vocabulary_widget(field, request, "display")
-
-def VocabularyBagFieldDisplayWidget(field, request):
- """Return a display widget based on a vocabulary field."""
- return _get_vocabulary_widget(field, request, "display-bag")
-
-def VocabularyListFieldDisplayWidget(field, request):
- """Return a display widget based on a vocabulary field."""
- return _get_vocabulary_widget(field, request, "display-list")
+class IVocabularyDisplayWidget(Interface):
+ pass
+
+class IVocabularyEditWidget(Interface):
+ pass
+
+class IVocabularyBagDisplayWidget(Interface):
+ pass
+
+class IVocabularyListDisplayWidget(Interface):
+ pass
+
+class IVocabularyMultiEditWidget(Interface):
+ pass
-def VocabularySetFieldDisplayWidget(field, request):
- """Return a display widget based on a vocabulary field."""
- return _get_vocabulary_widget(field, request, "display-set")
+# Marker interfaces for query view helpers
-def VocabularyUniqueListFieldDisplayWidget(field, request):
- """Return a display widget based on a vocabulary field."""
- return _get_vocabulary_widget(field, request, "display-unique-list")
+class IWidgetQueryHelper(Interface):
+ pass
+
+class IWidgetQueryListHelper(Interface):
+ pass
-# Edit
+# Factory functions to create vocabulary widgets for vocab field types
+
+def VocabularyFieldDisplayWidget(field, request):
+ return getVocabularyWidget(field, IVocabularyDisplayWidget, request)
def VocabularyFieldEditWidget(field, request):
- """Return a value-selection widget based on a vocabulary field."""
- return _get_vocabulary_edit_widget(field, request)
+ return getVocabularyWidget(field, IVocabularyEditWidget, request,
+ queryType=IWidgetQueryHelper)
+def VocabularyBagFieldDisplayWidget(field, request):
+ return getVocabularyWidget(field, IVocabularyBagDisplayWidget, request)
+
def VocabularyBagFieldEditWidget(field, request):
- """Return a value-selection widget based on a vocabulary field."""
- return _get_vocabulary_edit_widget(field, request, "bag")
-
-def VocabularyListFieldEditWidget(field, request):
- """Return a value-selection widget based on a vocabulary field."""
- return _get_vocabulary_edit_widget(field, request, "list")
+ # XXX not sure about IVocabularyMultiEditWidget - this is a guess
+ return getVocabularyWidget(field, IVocabularyMultiEditWidget, request,
+ queryType=IWidgetQueryListHelper)
-def VocabularySetFieldEditWidget(field, request):
- """Return a value-selection widget based on a vocabulary field."""
- return _get_vocabulary_edit_widget(field, request, "set")
+def VocabularyListFieldDisplayWidget(field, request):
+ return getVocabularyWidget(field, IVocabularyListDisplayWidget, request)
-def VocabularyUniqueListFieldEditWidget(field, request):
- """Return a value-selection widget based on a vocabulary field."""
- return _get_vocabulary_edit_widget(field, request, "unique-list")
+def VocabularyListFieldEditWidget(field, request):
+ return getVocabularyWidget(field, IVocabularyMultiEditWidget, request,
+ queryType=IWidgetQueryListHelper)
+def VocabularySetFieldDisplayWidget(field, request):
+ return getVocabularyWidget(field, IVocabularyBagDisplayWidget, request)
-# Helper functions for the factories:
+def VocabularySetFieldEditWidget(field, request):
+ # XXX not sure about IVocabularyMultiEditWidget - this is a guess
+ return getVocabularyWidget(field, IVocabularyMultiEditWidget, request,
+ queryType=IWidgetQueryListHelper)
-def _get_vocabulary_widget(field, request, viewname):
- view = zapi.getView(field.vocabulary,
- "field-%s-widget" % viewname, request)
- view = trustedRemoveSecurityProxy(view)
- view.setField(field)
- return view
-
-def _get_vocabulary_edit_widget(field, request, modifier=''):
- if modifier:
- modifier = "-" + modifier
- viewname = "edit" + modifier
- view = _get_vocabulary_widget(field, request, viewname)
- query = field.vocabulary.getQuery()
- if query is not None:
- queryname = "widget-query%s-helper" % modifier
- queryview = zapi.getView(query, queryname, request)
- view.setQuery(query, queryview)
- queryview.setWidget(view)
- return view
+def VocabularyUniqueListFieldDisplayWidget(field, request):
+ return getVocabularyWidget(field, IVocabularyListDisplayWidget, request)
+def VocabularyUniqueListFieldEditWidget(field, request):
+ # XXX not sure about IVocabularyMultiEditWidget - this is a guess
+ return getVocabularyWidget(field, IVocabularyMultiEditWidget, request,
+ queryType=IWidgetQueryListHelper)
+
+
+def getVocabularyWidget(field, widgetType, request, queryType=None):
+ """Returns a widget for a field vocabulary."""
+ widget = zapi.getViewProviding(field.vocabulary, widgetType, request)
+ widget.setField(field)
+ if queryType is not None:
+ query = field.vocabulary.getQuery()
+ if query is not None:
+ queryView = zapi.getViewProviding(query, queryType, request)
+ widget.setQuery(query, queryView)
+ queryView.setWidget(widget)
+ return widget
+
class IterableVocabularyQuery(object):
"""Simple query object used to invoke the simple selection mechanism."""
@@ -165,7 +174,7 @@
class VocabularyWidgetBase(ViewSupport, widget.BrowserWidget):
"""Convenience base class for vocabulary-based widgets."""
- propertyNames = widget.BrowserWidget.propertyNames + ["extra"]
+ propertyNames = ["extra"]
extra = ""
type = "vocabulary"
@@ -190,7 +199,7 @@
self.empty_marker_name = self.name + "-empty-marker"
def __call__(self):
- if self._data is self._data_marker:
+ if not self._renderedValueSet():
if self.hasInput():
try:
value = self.getInputValue()
@@ -311,6 +320,8 @@
class VocabularyDisplayWidget(SingleDataHelper, VocabularyWidgetBase):
"""Simple single-selection display that can be used in many cases."""
+
+ implements(IVocabularyDisplayWidget)
_msg_no_value = _msg_missing_single_value_display
@@ -324,8 +335,7 @@
class VocabularyMultiDisplayWidget(MultiDataHelper, VocabularyWidgetBase):
- propertyNames = (VocabularyWidgetBase.propertyNames
- + ['itemTag', 'tag'])
+ propertyNames = ['itemTag', 'tag']
itemTag = 'li'
tag = 'ol'
@@ -333,23 +343,23 @@
def render(self, value):
if value:
rendered_items = self.renderItems(value)
- return widget.renderElement(self.getValue('tag'),
- type=self.getValue('type'),
+ return widget.renderElement(self.tag,
+ type=self.inputType,
name=self.name,
id=self.name,
- cssClass=self.getValue('cssClass'),
+ cssClass=self.cssClass,
contents="\n".join(rendered_items),
- extra=self.getValue('extra'))
+ extra=self.extra)
else:
return self.translate(_msg_missing_multiple_value_display)
def renderItems(self, value):
L = []
vocabulary = self.context.vocabulary
- cssClass = self.getValue('cssClass') or ''
+ cssClass = self.cssClass or ''
if cssClass:
cssClass += "-item"
- tag = self.getValue('itemTag')
+ tag = self.itemTag
for v in value:
term = vocabulary.getTerm(v)
L.append(widget.renderElement(tag,
@@ -364,6 +374,9 @@
This can be used for both VocabularyListField and
VocabularyUniqueListField fields.
"""
+
+ implements(IVocabularyListDisplayWidget)
+
tag = 'ol'
@@ -373,6 +386,9 @@
This can be used for both VocabularyBagField and
VocabularySetField fields.
"""
+
+ implements(IVocabularyBagDisplayWidget)
+
tag = 'ul'
@@ -400,11 +416,13 @@
return ("<input type='submit' name='%s.action-%s' value=%s %s />"
% (self.name, action, quoteattr(self.translate(msgid)),
disabled and "\n disabled='disabled' " or ""))
-
-
+
+
class VocabularyEditWidgetBase(VocabularyWidgetBase):
- propertyNames = (VocabularyWidgetBase.propertyNames
- + ['size', 'tag'])
+
+ implements(IVocabularyEditWidget)
+
+ propertyNames = ['size', 'tag']
size = 5
tag = 'select'
@@ -446,7 +464,7 @@
s = self.queryview.renderInput()
if s:
contents.append(self._div('queryinput', s))
- return self._div(self.getValue('cssClass'), "\n".join(contents),
+ return self._div(self.cssClass, "\n".join(contents),
id=self.name)
def _div(self, cssClass, contents, **kw):
@@ -461,7 +479,7 @@
"""Render the list of possible values, with those found in
'values' being marked as selected."""
- cssClass = self.getValue('cssClass')
+ cssClass = self.cssClass
# multiple items with the same value are not allowed from a
# vocabulary, so that need not be considered here
@@ -508,7 +526,7 @@
to be small.
"""
implements(implementedBy(widget.SingleItemsWidget))
- propertyNames = VocabularyEditWidgetBase.propertyNames + ['firstItem']
+ propertyNames = ['firstItem']
firstItem = False
_msg_no_value = _msg_missing_single_value_edit
@@ -559,7 +577,7 @@
values = ()
L = self.renderItemsWithValues(values)
if not self.context.required:
- cssClass = self.getValue('cssClass')
+ cssClass = self.cssClass
kwargs = {
'value':'',
'name':self.name,
@@ -580,7 +598,7 @@
to be very large.
"""
implements(implementedBy(widget.SingleItemsWidget))
- propertyNames = VocabularyEditWidgetBase.propertyNames + ['firstItem']
+ propertyNames = ['firstItem']
firstItem = False
_msg_no_value = _msg_missing_single_value_edit
@@ -591,8 +609,8 @@
return widget.renderElement('select',
name=self.name,
contents=contents,
- size=self.getValue('size'),
- extra=self.getValue('extra'))
+ size=self.size,
+ extra=self.extra)
def renderItems(self, value):
vocabulary = self.context.vocabulary
@@ -623,6 +641,8 @@
class VocabularyMultiEditWidget(MultiDataHelper, VocabularyEditWidgetBase):
"""Vocabulary-backed widget supporting multiple selections."""
+
+ implements(IVocabularyMultiEditWidget)
_msg_no_value = _msg_missing_multiple_value_edit
@@ -637,12 +657,12 @@
# All we really add here is the ':list' in the name argument
# to widget.renderElement().
rendered_items = self.renderItems(value)
- return widget.renderElement(self.getValue('tag'),
+ return widget.renderElement(self.tag,
name=self.name + ':list',
multiple=None,
- size=self.getValue('size'),
+ size=self.size,
contents="\n".join(rendered_items),
- extra=self.getValue('extra'))
+ extra=self.extra)
class VocabularyQueryViewBase(ActionHelper, ViewSupport, BrowserView):
@@ -842,6 +862,8 @@
return value
class IterableVocabularyQueryView(IterableVocabularyQueryViewBase):
+
+ implements(IWidgetQueryHelper)
def makeSelectionList(self, items, name):
return self.mkselectionlist("radio", items, name)
@@ -851,6 +873,8 @@
results, [value])
class IterableVocabularyQueryMultiView(IterableVocabularyQueryViewBase):
+
+ implements(IWidgetQueryListHelper)
def makeSelectionList(self, items, name):
return self.mkselectionlist("checkbox", items, name)
=== Zope3/src/zope/app/browser/form/widget.py 1.64 => 1.64.14.1 ===
--- Zope3/src/zope/app/browser/form/widget.py:1.64 Wed Feb 4 14:17:29 2004
+++ Zope3/src/zope/app/browser/form/widget.py Thu Feb 26 00:10:49 2004
@@ -31,6 +31,7 @@
from zope.app import zapi
from zope.app.tests import ztapi
+from zope.app.interfaces.form import IEditWidget
from zope.app.interfaces.browser.form import IBrowserWidget
from zope.app.form.widget import Widget
from zope.app.form.utility import setUpEditWidgets, applyWidgetsChanges
@@ -50,6 +51,8 @@
labels, titles, and descriptions are translated and the
errors are rendered with the view machinery, so we need to set up
a lot of machinery to support translation and views:
+
+ XXX OZ - move the more complex testing into a test module
>>> setUp() # now we have to set up an error view...
>>> from zope.app.interfaces.form import IWidgetInputError
@@ -138,30 +141,18 @@
Now we clean up.
>>> tearDown()
-
"""
implements(IBrowserWidget)
- propertyNames = (Widget.propertyNames +
- ['tag', 'type', 'cssClass', 'extra'])
-
tag = 'input'
- type = 'text'
+ inputType = 'text'
cssClass = ''
extra = ''
_missing = ''
_error = None
-
- def haveData(self):
- if traceback.extract_stack()[-2][2] != 'hasInput':
- warn("haveData is deprecated - use hasInput",
- DeprecationWarning, 2)
-
- # XXX - move this implementation to hasInput when deprecation is
- # removed
-
- return self.name in self.request.form
+
+ required = property(lambda self: self.context.required)
def hasInput(self):
"""See IWidget.hasInput.
@@ -174,7 +165,7 @@
forms when their value is 'off' -- in this case the widget will
need to add a hidden element to signal its presence in the form.
"""
- return self.haveData()
+ return self.name in self.request.form
def hasValidInput(self):
try:
@@ -183,14 +174,7 @@
except WidgetInputError:
return False
- def getData(self):
- if traceback.extract_stack()[-2][2] != 'getInputValue':
- warn("getData is deprecated - use getInputValue",
- DeprecationWarning, 2)
-
- # XXX - move this implementation to getInputValue when deprecation
- # is removed
-
+ def getInputValue(self):
self._error = None
field = self.context
@@ -215,9 +199,6 @@
raise self._error
return value
- def getInputValue(self):
- return self.getData()
-
def validate(self):
self.getInputValue()
@@ -263,7 +244,7 @@
def _showData(self):
"""Returns a value suitable for use as an HTML form value."""
- if self._data is self._data_marker:
+ if not self._renderedValueSet():
if self.hasInput():
try:
value = self.getInputValue()
@@ -282,22 +263,22 @@
return self.context.default
def __call__(self):
- return renderElement(self.getValue('tag'),
- type = self.getValue('type'),
- name = self.name,
- id = self.name,
- value = self._showData(),
- cssClass = self.getValue('cssClass'),
- extra = self.getValue('extra'))
+ return renderElement(self.tag,
+ type=self.inputType,
+ name=self.name,
+ id=self.name,
+ value=self._showData(),
+ cssClass=self.cssClass,
+ extra=self.extra)
def hidden(self):
- return renderElement(self.getValue('tag'),
- type = 'hidden',
- name = self.name,
- id = self.name,
- value = self._showData(),
- cssClass = self.getValue('cssClass'),
- extra = self.getValue('extra'))
+ return renderElement(self.tag,
+ type='hidden',
+ name=self.name,
+ id=self.name,
+ value=self._showData(),
+ cssClass=self.cssClass,
+ extra=self.extra)
def render(self, value):
warn("The widget render method is deprecated",
@@ -335,92 +316,25 @@
self.error())
else:
return '<div class="%s">%s</div><div class="field">%s</div>' % (
- self.labelClass(), self.label(), self()
- )
+ self.labelClass(), self.label(), self())
+
class DisplayWidget(BrowserWidget):
def __call__(self):
return self._showData()
+
class CheckBoxWidget(BrowserWidget):
- """Checkbox widget
-
- >>> from zope.publisher.browser import TestRequest
- >>> from zope.schema import Bool
- >>> field = Bool(__name__='foo', title=u'on')
- >>> request = TestRequest(form={'field.foo.used': u'on',
- ... 'field.foo': u'on'})
- >>> widget = CheckBoxWidget(field, request)
- >>> widget.hasInput()
- True
- >>> widget.getInputValue()
- True
-
- >>> def normalize(s):
- ... return '\\n '.join(s.split())
-
- >>> print normalize( widget() )
- <input
- class="hiddenType"
- id="field.foo.used"
- name="field.foo.used"
- type="hidden"
- value=""
- />
- <input
- class="checkboxType"
- checked="checked"
- id="field.foo"
- name="field.foo"
- type="checkbox"
- />
-
- >>> print normalize( widget.hidden() )
- <input
- class="hiddenType"
- id="field.foo"
- name="field.foo"
- type="hidden"
- value="on"
- />
-
- Calling setRenderedValue will change what gets output:
-
- >>> widget.setRenderedValue(False)
- >>> print normalize( widget() )
- <input
- class="hiddenType"
- id="field.foo.used"
- name="field.foo.used"
- type="hidden"
- value=""
- />
- <input
- class="checkboxType"
- id="field.foo"
- name="field.foo"
- type="checkbox"
- />
-
- When a checkbox is not 'checked', it's value is not
- sent in the request, so we consider it 'False', which
- means that 'required' for a boolean field doesn't make
- much sense in the end.
-
- >>> field = Bool(__name__='foo', title=u'on', required=True)
- >>> request = TestRequest(form={'field.foo.used': u''})
- >>> widget = CheckBoxWidget(field, request)
- >>> widget.hasInput()
- True
- >>> widget.validate()
- >>> widget.getInputValue()
- False
+ """A checkbox widget used to display Bool fields.
+
+ For more detailed documentation, including sample code, see
+ tests/test_checkboxwidget.py.
"""
- propertyNames = BrowserWidget.propertyNames + \
- ['extra', 'default']
-
- type = 'checkbox'
+
+ implements(IEditWidget)
+
+ inputType = 'checkbox'
default = 0
extra = ''
@@ -431,18 +345,18 @@
else:
kw = {}
return "%s %s" % (
- renderElement(self.getValue('tag'),
- type = 'hidden',
- name = self.name+".used",
- id = self.name+".used",
+ renderElement(self.tag,
+ type='hidden',
+ name=self.name+".used",
+ id=self.name+".used",
value=""
),
- renderElement(self.getValue('tag'),
- type = self.getValue('type'),
- name = self.name,
- id = self.name,
- cssClass = self.getValue('cssClass'),
- extra = self.getValue('extra'),
+ renderElement(self.tag,
+ type=self.inputType,
+ name=self.name,
+ id=self.name,
+ cssClass=self.cssClass,
+ extra=self.extra,
**kw),
)
@@ -515,9 +429,9 @@
/>
"""
- propertyNames = (BrowserWidget.propertyNames +
- ['displayWidth', 'displayMaxWidth', 'extra', 'default']
- )
+
+ implements(IEditWidget)
+
default = ''
displayWidth = 20
displayMaxWidth = ""
@@ -531,28 +445,28 @@
super(TextWidget, self).__init__(*args)
def __call__(self):
- displayMaxWidth = self.getValue('displayMaxWidth') or 0
+ displayMaxWidth = self.displayMaxWidth or 0
if displayMaxWidth > 0:
- return renderElement(self.getValue('tag'),
- type = self.getValue('type'),
- name = self.name,
- id = self.name,
- value = self._showData(),
- cssClass = self.getValue('cssClass'),
- style = self.style,
- size = self.getValue('displayWidth'),
- maxlength = displayMaxWidth,
- extra = self.getValue('extra'))
+ return renderElement(self.tag,
+ type=self.inputType,
+ name=self.name,
+ id=self.name,
+ value=self._showData(),
+ cssClass=self.cssClass,
+ style=self.style,
+ size=self.displayWidth,
+ maxlength=displayMaxWidth,
+ extra=self.extra)
else:
- return renderElement(self.getValue('tag'),
- type = self.getValue('type'),
- name = self.name,
- id = self.name,
- value = self._showData(),
- cssClass = self.getValue('cssClass'),
- style = self.style,
- size = self.getValue('displayWidth'),
- extra = self.getValue('extra'))
+ return renderElement(self.tag,
+ type=self.inputType,
+ name=self.name,
+ id=self.name,
+ value=self._showData(),
+ cssClass=self.cssClass,
+ style=self.style,
+ size=self.displayWidth,
+ extra=self.extra)
class Bytes(BrowserWidget):
@@ -565,6 +479,7 @@
raise ConversionError("Invalid textual data", v)
return value
+
class BytesWidget(Bytes, TextWidget):
"""Bytes widget.
@@ -580,11 +495,12 @@
True
>>> widget.getInputValue()
'Bob'
- """
+ """
class ASCII(Bytes):
- """ ASCII
- """
+ """ASCII"""
+ # XXX OZ fix
+
class ASCIIWidget(BytesWidget):
"""ASCII widget.
@@ -593,6 +509,7 @@
"""
class IntWidget(TextWidget):
+
displayWidth = 10
def _convert(self, value):
@@ -603,8 +520,11 @@
return int(value)
except ValueError, v:
raise ConversionError("Invalid integer data", v)
+
class FloatWidget(TextWidget):
+
+ implements(IEditWidget)
displayWidth = 10
def _convert(self, value):
@@ -615,9 +535,11 @@
return float(value)
except ValueError, v:
raise ConversionError("Invalid floating point data", v)
+
class DatetimeWidget(TextWidget):
"""Datetime entry widget."""
+
displayWidth = 20
def _convert(self, value):
@@ -628,10 +550,12 @@
return parseDatetimetz(value)
except (DateTimeError, ValueError, IndexError), v:
raise ConversionError("Invalid datetime data", v)
+
class DateWidget(TextWidget):
"""Date entry widget.
"""
+
displayWidth = 20
def _convert(self, value):
@@ -642,6 +566,7 @@
return parseDatetimetz(value).date()
except (DateTimeError, ValueError, IndexError), v:
raise ConversionError("Invalid datetime data", v)
+
class TextAreaWidget(BrowserWidget):
"""TextArea widget.
@@ -693,7 +618,8 @@
dude!</textarea>
"""
- propertyNames = BrowserWidget.propertyNames + ['width', 'height', 'extra']
+
+ implements(IEditWidget)
default = ""
width = 60
@@ -715,14 +641,14 @@
def __call__(self):
return renderElement("textarea",
- name = self.name,
- id = self.name,
- cssClass = self.getValue('cssClass'),
- rows = self.getValue('height'),
- cols = self.getValue('width'),
- style = self.style,
- contents = self._showData(),
- extra = self.getValue('extra'))
+ name=self.name,
+ id=self.name,
+ cssClass=self.cssClass,
+ rows=self.height,
+ cols=self.width,
+ style=self.style,
+ contents=self._showData(),
+ extra=self.extra)
class BytesAreaWidget(Bytes, TextAreaWidget):
"""BytesArea widget.
@@ -738,64 +664,66 @@
True
>>> widget.getInputValue()
'Hello\\nworld!'
-
- """
+ """
class PasswordWidget(TextWidget):
"""Password Widget"""
- type='password'
+
+ inputType = 'password'
def __call__(self):
- displayMaxWidth = self.getValue('displayMaxWidth') or 0
+ displayMaxWidth = self.displayMaxWidth or 0
if displayMaxWidth > 0:
- return renderElement(self.getValue('tag'),
- type = self.getValue('type'),
- name = self.name,
- id = self.name,
- value = '',
- cssClass = self.getValue('cssClass'),
- style = self.style,
- size = self.getValue('displayWidth'),
- maxlength = displayMaxWidth,
- extra = self.getValue('extra'))
+ return renderElement(self.tag,
+ type=self.inputType,
+ name=self.name,
+ id=self.name,
+ value='',
+ cssClass=self.cssClass,
+ style=self.style,
+ size=self.displayWidth,
+ maxlength=displayMaxWidth,
+ extra=self.extra)
else:
- return renderElement(self.getValue('tag'),
- type = self.getValue('type'),
- name = self.name,
- id = self.name,
- value = '',
- cssClass = self.getValue('cssClass'),
- style = self.style,
- size = self.getValue('displayWidth'),
- extra = self.getValue('extra'))
+ return renderElement(self.tag,
+ type=self.inputType,
+ name=self.name,
+ id=self.name,
+ value='',
+ cssClass=self.cssClass,
+ style=self.style,
+ size=self.displayWidth,
+ extra=self.extra)
def hidden(self):
raise NotImplementedError(
'Cannot get a hidden tag for a password field')
+
class FileWidget(TextWidget):
"""File Widget"""
- type = 'file'
+
+ inputType = 'file'
def __call__(self):
- displayMaxWidth = self.getValue('displayMaxWidth') or 0
+ displayMaxWidth = self.displayMaxWidth or 0
if displayMaxWidth > 0:
- return renderElement(self.getValue('tag'),
- type = self.getValue('type'),
- name = self.name,
- id = self.name,
- cssClass = self.getValue('cssClass'),
- size = self.getValue('displayWidth'),
- maxlength = displayMaxWidth,
- extra = self.getValue('extra'))
+ return renderElement(self.tag,
+ type=self.inputType,
+ name=self.name,
+ id=self.name,
+ cssClass=self.cssClass,
+ size=self.displayWidth,
+ maxlength=displayMaxWidth,
+ extra=self.extra)
else:
- return renderElement(self.getValue('tag'),
- type = self.getValue('type'),
- name = self.name,
- id = self.name,
- cssClass = self.getValue('cssClass'),
- size = self.getValue('displayWidth'),
- extra = self.getValue('extra'))
+ return renderElement(self.tag,
+ type=self.inputType,
+ name=self.name,
+ id=self.name,
+ cssClass=self.cssClass,
+ size=self.displayWidth,
+ extra=self.extra)
def hasInput(self):
file = self.request.form.get(self.name)
@@ -834,13 +762,15 @@
class ItemsWidget(BrowserWidget):
"""A widget that has a number of items in it."""
-
# What the heck is this for?
-
+
+ implements(IEditWidget)
+
class SingleItemsWidget(ItemsWidget):
"""A widget with a number of items that has only a single
- selectable item."""
+ selectable item.""" # XXX OZ fix
+
default = ""
firstItem = False
@@ -866,7 +796,7 @@
and len(items) > 0):
value = items[0]
- cssClass = self.getValue('cssClass')
+ cssClass = self.cssClass
# FIXME: what if we run into multiple items with same value?
rendered_items = []
@@ -895,20 +825,18 @@
class ListWidget(SingleItemsWidget):
"""List widget."""
- propertyNames = (SingleItemsWidget.propertyNames +
- ['firstItem', 'items', 'size', 'extra']
- )
+
size = 5
def __call__(self):
renderedItems = self.renderItems(self._showData())
return renderElement('select',
- name = self.name,
- id = self.name,
- cssClass = self.getValue('cssClass'),
- size = self.getValue('size'),
- contents = "\n".join(renderedItems),
- extra = self.getValue('extra'))
+ name=self.name,
+ id=self.name,
+ cssClass=self.cssClass,
+ size=self.size,
+ contents="\n".join(renderedItems),
+ extra=self.extra)
def renderItem(self, index, text, value, name, cssClass):
return renderElement('option', contents=text, value=value,
@@ -921,13 +849,12 @@
class RadioWidget(SingleItemsWidget):
"""Radio buttons widget."""
- propertyNames = SingleItemsWidget.propertyNames +\
- ['firstItem', 'orientation']
+
orientation = "vertical"
def __call__(self):
rendered_items = self.renderItems(self._showData())
- orientation = self.getValue('orientation')
+ orientation = self.orientation
if orientation == 'horizontal':
return " ".join(rendered_items)
else:
@@ -970,11 +897,12 @@
def row(self):
return ('<div class="%s"><label for="%s">%s</label></div>'
'<div class="field" id="%s">%s</div>' % (
- self.labelClass(), self.name, self.label(), self.name, self())
- )
+ self.labelClass(), self.name, self.label(), self.name, self()))
+
class MultiItemsWidget(ItemsWidget):
"""A widget with a number of items that has multiple selectable items."""
+
default = []
def _convert(self, value):
@@ -992,7 +920,7 @@
value = [value]
name = self.name
items = self.context.allowed_values
- cssClass = self.getValue('cssClass')
+ cssClass = self.cssClass
rendered_items = []
count = 0
for item in items:
@@ -1023,7 +951,7 @@
class MultiListWidget(MultiItemsWidget):
"""List widget with multiple select."""
- propertyNames = MultiItemsWidget.propertyNames + ['size', 'extra']
+
size = 5
def __call__(self):
@@ -1032,10 +960,10 @@
name=self.name,
id=self.name,
multiple=None,
- cssClass=self.getValue('cssClass'),
- size=self.getValue('size'),
+ cssClass=self.cssClass,
+ size=self.size,
contents="\n".join(rendered_items),
- extra=self.getValue('extra'))
+ extra=self.extra)
def renderItem(self, index, text, value, name, cssClass):
return renderElement('option', contents=text, value=value)
@@ -1047,12 +975,12 @@
class MultiCheckBoxWidget(MultiItemsWidget):
"""Multiple checkbox widget."""
- propertyNames = MultiItemsWidget.propertyNames + ['orientation']
+
orientation = "vertical"
def __call__(self):
rendered_items = self.renderItems(self._showData())
- orientation = self.getValue('orientation')
+ orientation = self.orientation
if orientation == 'horizontal':
return " ".join(rendered_items)
else:
@@ -1074,14 +1002,18 @@
id=name,
value=value,
checked=None) + text
+
class SequenceWidget(BrowserWidget):
- """A sequence of fields.
+ """A widget baseclass for a sequence of fields.
subwidget - Optional CustomWidget used to generate widgets for the
items in the sequence
"""
- _type = tuple
+
+ implements(IEditWidget)
+
+ _type = tuple
_data = () # pre-existing sequence items (from setRenderedValue)
def __init__(self, context, request, subwidget=None):
@@ -1151,7 +1083,8 @@
if self.subwidget:
widget = self.subwidget(field, self.request)
else:
- widget = zapi.getView(field, 'edit', self.request, self.context)
+ widget = zapi.getViewProviding(field, IEditWidget, self.request,
+ context=self.context)
widget.setPrefix('%s.%d.'%(self.name, i))
return widget
@@ -1275,12 +1208,15 @@
return sequence
+
class TupleSequenceWidget(SequenceWidget):
pass
class ListSequenceWidget(SequenceWidget):
+
_type = list
+
class ObjectWidget(BrowserWidget):
"""A widget over an Interface that contains Fields.
@@ -1288,7 +1224,22 @@
represents
*_widget - Optional CustomWidgets used to generate widgets for the
fields in this widget
+
+ XXX This widget will not work with the default widget lookup scheme
+ because its initializer requires an additional 'factory' argument.
+ We should consider enhancing IObject to provide a factory function
+ to create an instance of the IObject schema. This would replace this
+ widget's factory facility. E.g.
+
+ class IFoo:
+ bar = Object(schema=IBar, factory=Bar)
+
+ This would be enough information for the object widget to render bar
+ fields (bound) and create default values for bar.
"""
+
+ implements(IEditWidget)
+
_object = None # the object value (from setRenderedValue & request)
_request_parsed = False
@@ -1314,8 +1265,8 @@
def _setUpEditWidgets(self):
# subwidgets need a new name
- setUpEditWidgets(self, self.context.schema, content=None,
- prefix=self.name, names=self.names, context=self.context)
+ setUpEditWidgets(self, self.context.schema, prefix=self.name,
+ names=self.names, context=self.context)
def __call__(self):
"""Render the widget
@@ -1371,8 +1322,8 @@
# apply sub changes, see if there *are* any changes
# XXX ObjectModifiedEvent here would be nice
- changes = applyWidgetsChanges(self, value, field.schema,
- names=self.names, exclude_readonly=True)
+ changes = applyWidgetsChanges(self, field.schema,
+ names=self.names, context=value)
# if there's changes, then store the new value on the content
if changes:
@@ -1400,6 +1351,7 @@
self._setUpEditWidgets()
for name, widget in self.getSubWidgets():
widget.setRenderedValue(getattr(value, name, None))
+
# XXX Note, some HTML quoting is needed in renderTag and renderElement.
@@ -1463,12 +1415,14 @@
return "%s>%s</%s>" % (renderTag(tag, **kw), contents, tag)
else:
return renderTag(tag, **kw) + " />"
+
def setUp():
import zope.app.tests.placelesssetup
global setUp
setUp = zope.app.tests.placelesssetup.setUp
setUp()
+
def tearDown():
import zope.app.tests.placelesssetup
More information about the Zope3-Checkins
mailing list