def setupFormDefaults(): # Validator adapters zope.component.provideAdapter(validator.SimpleFieldValidator) zope.component.provideAdapter(validator.InvariantsValidator) # Data manager adapter to get and set values to content zope.component.provideAdapter(datamanager.AttributeField) # Adapter to use form.fields to generate widgets zope.component.provideAdapter(field.FieldWidgets) # Adapter that uses form.fields to generate widgets # AND interlace content providers zope.component.provideAdapter(contentprovider.FieldWidgetsAndProviders) # Adapters to lookup the widget for a field # Text Field Widget zope.component.provideAdapter( text.TextFieldWidget, adapts=(zope.schema.interfaces.IBytesLine, interfaces.IFormLayer)) zope.component.provideAdapter( text.TextFieldWidget, adapts=(zope.schema.interfaces.IASCIILine, interfaces.IFormLayer)) zope.component.provideAdapter( text.TextFieldWidget, adapts=(zope.schema.interfaces.ITextLine, interfaces.IFormLayer)) zope.component.provideAdapter( text.TextFieldWidget, adapts=(zope.schema.interfaces.IId, interfaces.IFormLayer)) zope.component.provideAdapter( text.TextFieldWidget, adapts=(zope.schema.interfaces.IInt, interfaces.IFormLayer)) zope.component.provideAdapter( text.TextFieldWidget, adapts=(zope.schema.interfaces.IFloat, interfaces.IFormLayer)) zope.component.provideAdapter( text.TextFieldWidget, adapts=(zope.schema.interfaces.IDecimal, interfaces.IFormLayer)) zope.component.provideAdapter( text.TextFieldWidget, adapts=(zope.schema.interfaces.IDate, interfaces.IFormLayer)) zope.component.provideAdapter( text.TextFieldWidget, adapts=(zope.schema.interfaces.IDatetime, interfaces.IFormLayer)) zope.component.provideAdapter( text.TextFieldWidget, adapts=(zope.schema.interfaces.ITime, interfaces.IFormLayer)) zope.component.provideAdapter( text.TextFieldWidget, adapts=(zope.schema.interfaces.ITimedelta, interfaces.IFormLayer)) zope.component.provideAdapter( text.TextFieldWidget, adapts=(zope.schema.interfaces.IURI, interfaces.IFormLayer)) # Widget Layout zope.component.provideAdapter( widget.WidgetLayoutFactory(getPath('widget_layout.pt'), 'text/html'), (None, None, None, None, interfaces.IWidget), interfaces.IWidgetLayoutTemplate, name=interfaces.INPUT_MODE) zope.component.provideAdapter( widget.WidgetLayoutFactory(getPath('widget_layout.pt'), 'text/html'), (None, None, None, None, interfaces.IWidget), interfaces.IWidgetLayoutTemplate, name=interfaces.DISPLAY_MODE) zope.component.provideAdapter( widget.WidgetLayoutFactory(getPath('widget_layout_hidden.pt'), 'text/html'), (None, None, None, None, interfaces.IWidget), interfaces.IWidgetLayoutTemplate, name=interfaces.HIDDEN_MODE) # Text Field Widget zope.component.provideAdapter( widget.WidgetTemplateFactory(getPath('text_input.pt'), 'text/html'), (None, None, None, None, interfaces.ITextWidget), IPageTemplate, name=interfaces.INPUT_MODE) zope.component.provideAdapter( widget.WidgetTemplateFactory(getPath('text_display.pt'), 'text/html'), (None, None, None, None, interfaces.ITextWidget), IPageTemplate, name=interfaces.DISPLAY_MODE) zope.component.provideAdapter( widget.WidgetTemplateFactory(getPath('text_hidden.pt'), 'text/html'), (None, None, None, None, interfaces.ITextWidget), IPageTemplate, name=interfaces.HIDDEN_MODE) # Textarea Field Widget zope.component.provideAdapter( textarea.TextAreaFieldWidget, adapts=(zope.schema.interfaces.IASCII, interfaces.IFormLayer)) zope.component.provideAdapter( textarea.TextAreaFieldWidget, adapts=(zope.schema.interfaces.IText, interfaces.IFormLayer)) zope.component.provideAdapter( widget.WidgetTemplateFactory(getPath('textarea_input.pt'), 'text/html'), (None, None, None, None, interfaces.ITextAreaWidget), IPageTemplate, name=interfaces.INPUT_MODE) zope.component.provideAdapter( widget.WidgetTemplateFactory(getPath('textarea_display.pt'), 'text/html'), (None, None, None, None, interfaces.ITextAreaWidget), IPageTemplate, name=interfaces.DISPLAY_MODE) # Radio Field Widget zope.component.provideAdapter(radio.RadioFieldWidget) zope.component.provideAdapter( widget.WidgetTemplateFactory(getPath('radio_input.pt'), 'text/html'), (None, None, None, None, interfaces.IRadioWidget), IPageTemplate, name=interfaces.INPUT_MODE) zope.component.provideAdapter( widget.WidgetTemplateFactory(getPath('radio_display.pt'), 'text/html'), (None, None, None, None, interfaces.IRadioWidget), IPageTemplate, name=interfaces.DISPLAY_MODE) zope.component.provideAdapter( widget.WidgetTemplateFactory(getPath('radio_input_single.pt'), 'text/html'), (None, None, None, None, interfaces.IRadioWidget), IPageTemplate, name='input_single') zope.component.provideAdapter( widget.WidgetTemplateFactory(getPath('radio_hidden_single.pt'), 'text/html'), (None, None, None, None, interfaces.IRadioWidget), IPageTemplate, name='hidden_single') # Select Widget zope.component.provideAdapter(select.ChoiceWidgetDispatcher) zope.component.provideAdapter(select.SelectFieldWidget) zope.component.provideAdapter( widget.WidgetTemplateFactory(getPath('select_input.pt'), 'text/html'), (None, None, None, None, interfaces.ISelectWidget), IPageTemplate, name=interfaces.INPUT_MODE) zope.component.provideAdapter( widget.WidgetTemplateFactory(getPath('select_display.pt'), 'text/html'), (None, None, None, None, interfaces.ISelectWidget), IPageTemplate, name=interfaces.DISPLAY_MODE) zope.component.provideAdapter( widget.WidgetTemplateFactory(getPath('select_hidden.pt'), 'text/html'), (None, None, None, None, interfaces.ISelectWidget), IPageTemplate, name=interfaces.HIDDEN_MODE) # Checkbox Field Widget; register only templates zope.component.provideAdapter( widget.WidgetTemplateFactory(getPath('checkbox_input.pt'), 'text/html'), (None, None, None, None, interfaces.ICheckBoxWidget), IPageTemplate, name=interfaces.INPUT_MODE) zope.component.provideAdapter( widget.WidgetTemplateFactory( getPath('checkbox_display.pt'), 'text/html'), (None, None, None, None, interfaces.ICheckBoxWidget), IPageTemplate, name=interfaces.DISPLAY_MODE) # Submit Field Widget zope.component.provideAdapter( widget.WidgetTemplateFactory(getPath('submit_input.pt'), 'text/html'), (None, None, None, None, interfaces.ISubmitWidget), IPageTemplate, name=interfaces.INPUT_MODE) # selectwidget helper adapters zope.component.provideAdapter(select.CollectionSelectFieldWidget) zope.component.provideAdapter(select.CollectionChoiceSelectFieldWidget) # Adapter to convert between field/internal and widget values zope.component.provideAdapter(converter.FieldDataConverter) zope.component.provideAdapter(converter.SequenceDataConverter) zope.component.provideAdapter(converter.CollectionSequenceDataConverter) zope.component.provideAdapter(converter.FieldWidgetDataConverter) # special data converter zope.component.provideAdapter(converter.IntegerDataConverter) zope.component.provideAdapter(converter.FloatDataConverter) zope.component.provideAdapter(converter.DecimalDataConverter) zope.component.provideAdapter(converter.DateDataConverter) zope.component.provideAdapter(converter.TimeDataConverter) zope.component.provideAdapter(converter.DatetimeDataConverter) zope.component.provideAdapter(converter.TimedeltaDataConverter) # Adapter for providing terms to radio list and other widgets zope.component.provideAdapter(term.BoolTerms) zope.component.provideAdapter(term.ChoiceTerms) zope.component.provideAdapter(term.ChoiceTermsVocabulary) zope.component.provideAdapter(term.ChoiceTermsSource) zope.component.provideAdapter(term.CollectionTerms) zope.component.provideAdapter(term.CollectionTermsVocabulary) zope.component.provideAdapter(term.CollectionTermsSource) # Adapter to create an action from a button zope.component.provideAdapter( button.ButtonAction, provides=interfaces.IButtonAction) # Adapter to use form.buttons to generate actions zope.component.provideAdapter(button.ButtonActions) # Adapter to use form.handlers to generate handle actions zope.component.provideAdapter(button.ButtonActionHandler) # Subscriber handling action execution error events zope.component.provideHandler(form.handleActionError) # Error View(s) zope.component.provideAdapter(error.ErrorViewSnippet) zope.component.provideAdapter(error.InvalidErrorViewSnippet) zope.component.provideAdapter(error.StandardErrorViewTemplate)
def setup_defaults(): # Set up z3c.form defaults from z3c.form import browser, button, converter, datamanager, error, field from z3c.form import interfaces, validator, widget from z3c.form.browser import text from zope.pagetemplate.interfaces import IPageTemplate import os.path import zope.schema def getPath(filename): return os.path.join(os.path.dirname(browser.__file__), filename) component.provideAdapter(validator.SimpleFieldValidator) component.provideAdapter(validator.InvariantsValidator) component.provideAdapter(datamanager.AttributeField) component.provideAdapter(field.FieldWidgets) component.provideAdapter( text.TextFieldWidget, adapts=(zope.schema.interfaces.ITextLine, interfaces.IFormLayer)) component.provideAdapter( text.TextFieldWidget, adapts=(zope.schema.interfaces.IInt, interfaces.IFormLayer)) component.provideAdapter( widget.WidgetTemplateFactory(getPath('text_input.pt'), 'text/html'), (None, None, None, None, interfaces.ITextWidget), IPageTemplate, name=interfaces.INPUT_MODE) component.provideAdapter( widget.WidgetTemplateFactory(getPath('text_display.pt'), 'text/html'), (None, None, None, None, interfaces.ITextWidget), IPageTemplate, name=interfaces.DISPLAY_MODE) component.provideAdapter( widget.WidgetTemplateFactory( getPath('checkbox_input.pt'), 'text/html'), (None, None, None, None, interfaces.ICheckBoxWidget), IPageTemplate, name=interfaces.INPUT_MODE) component.provideAdapter( widget.WidgetTemplateFactory( getPath('checkbox_display.pt'), 'text/html'), (None, None, None, None, interfaces.ICheckBoxWidget), IPageTemplate, name=interfaces.DISPLAY_MODE) # Submit Field Widget component.provideAdapter( widget.WidgetTemplateFactory(getPath('submit_input.pt'), 'text/html'), (None, None, None, None, interfaces.ISubmitWidget), IPageTemplate, name=interfaces.INPUT_MODE) component.provideAdapter(converter.FieldDataConverter) component.provideAdapter(converter.FieldWidgetDataConverter) component.provideAdapter( button.ButtonAction, provides=interfaces.IButtonAction) component.provideAdapter(button.ButtonActions) component.provideAdapter(button.ButtonActionHandler) component.provideAdapter(error.StandardErrorViewTemplate) # Make traversal work; register both the default traversable # adapter and the ++view++ namespace adapter component.provideAdapter( zope.traversing.adapters.DefaultTraversable, [None]) component.provideAdapter( zope.traversing.namespace.view, (None, None), name='view') # Setup ploneform macros, simlulating the ZCML directive plone.z3cform.templates.Macros.index = ViewPageTemplateFile( plone.z3cform.templates.path('macros.pt')) component.provideAdapter( plone.z3cform.templates.Macros, (None, None), zope.publisher.interfaces.browser.IBrowserView, name='ploneform-macros') # setup plone.z3cform templates from zope.pagetemplate.interfaces import IPageTemplate component.provideAdapter( plone.z3cform.templates.wrapped_form_factory, (None, None), IPageTemplate) from z3c.form.interfaces import IErrorViewSnippet component.provideAdapter( error.ErrorViewSnippet, (None, None, None, None, None, None), IErrorViewSnippet)
def setupFormDefaults(): # Validator adapters zope.component.provideAdapter(validator.SimpleFieldValidator) zope.component.provideAdapter(validator.InvariantsValidator) # Data manager adapter to get and set values to content zope.component.provideAdapter(datamanager.AttributeField) # Adapter to use form.fields to generate widgets zope.component.provideAdapter(field.FieldWidgets) # Adapters to lookup the widget for a field # Text Field Widget zope.component.provideAdapter(text.TextFieldWidget, adapts=(zope.schema.interfaces.ITextLine, interfaces.IFormLayer)) zope.component.provideAdapter(text.TextFieldWidget, adapts=(zope.schema.interfaces.IInt, interfaces.IFormLayer)) zope.component.provideAdapter(widget.WidgetTemplateFactory( getPath('text_input.pt'), 'text/html'), (None, None, None, None, interfaces.ITextWidget), IPageTemplate, name=interfaces.INPUT_MODE) zope.component.provideAdapter(widget.WidgetTemplateFactory( getPath('text_display.pt'), 'text/html'), (None, None, None, None, interfaces.ITextWidget), IPageTemplate, name=interfaces.DISPLAY_MODE) zope.component.provideAdapter(widget.WidgetTemplateFactory( getPath('text_hidden.pt'), 'text/html'), (None, None, None, None, interfaces.ITextWidget), IPageTemplate, name=interfaces.HIDDEN_MODE) # Radio Field Widget zope.component.provideAdapter(radio.RadioFieldWidget) zope.component.provideAdapter(widget.WidgetTemplateFactory( getPath('radio_input.pt'), 'text/html'), (None, None, None, None, interfaces.IRadioWidget), IPageTemplate, name=interfaces.INPUT_MODE) zope.component.provideAdapter(widget.WidgetTemplateFactory( getPath('radio_display.pt'), 'text/html'), (None, None, None, None, interfaces.IRadioWidget), IPageTemplate, name=interfaces.DISPLAY_MODE) # Select Field Widget zope.component.provideAdapter(select.SelectFieldWidget) zope.component.provideAdapter(widget.WidgetTemplateFactory( getPath('select_input.pt'), 'text/html'), (None, None, None, None, interfaces.ISelectWidget), IPageTemplate, name=interfaces.INPUT_MODE) zope.component.provideAdapter(widget.WidgetTemplateFactory( getPath('select_display.pt'), 'text/html'), (None, None, None, None, interfaces.ISelectWidget), IPageTemplate, name=interfaces.DISPLAY_MODE) # Submit Field Widget zope.component.provideAdapter(widget.WidgetTemplateFactory( getPath('submit_input.pt'), 'text/html'), (None, None, None, None, interfaces.ISubmitWidget), IPageTemplate, name=interfaces.INPUT_MODE) # selectwidget helper adapters zope.component.provideAdapter(select.CollectionSelectFieldWidget) zope.component.provideAdapter(select.CollectionChoiceSelectFieldWidget) # Adapter to convert between field/internal and widget values zope.component.provideAdapter(converter.FieldDataConverter) zope.component.provideAdapter(converter.SequenceDataConverter) zope.component.provideAdapter(converter.FieldWidgetDataConverter) # Adapter for providing terms to radio list and other widgets zope.component.provideAdapter(term.ChoiceTerms) zope.component.provideAdapter(term.BoolTerms) # Adapter to create an action from a button zope.component.provideAdapter(button.ButtonAction, provides=interfaces.IButtonAction) # Adapter to use form.buttons to generate actions zope.component.provideAdapter(button.ButtonActions) # Adapter to use form.handlers to generate handle actions zope.component.provideAdapter(button.ButtonActionHandler) # Error View(s) zope.component.provideAdapter(error.ErrorViewSnippet) zope.component.provideAdapter(error.StandardErrorViewTemplate)