Skip to content
This repository has been archived by the owner on Apr 9, 2019. It is now read-only.

Commit

Permalink
More Python 2 / 3 compatibility adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
davilima6 committed Jan 31, 2018
1 parent fefbc94 commit 417b17a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
4 changes: 2 additions & 2 deletions CHANGES.rst
Expand Up @@ -10,8 +10,8 @@ Bug fixes:

New features:

- Add Python 2 / 3 compatibility
[pbauer]
- Prepare for Python 2 / 3 compatibility
[pbauer, davilima6]


0.9.1 (2017-09-03)
Expand Down
4 changes: 2 additions & 2 deletions src/plone/z3cform/inputs.txt
Expand Up @@ -38,7 +38,7 @@ Then we create and register a simple form that expects unicode text input:
... @button.buttonAndHandler(u'Apply')
... def handleApply(self, action):
... data, errors = self.extractData()
... print repr(data['text'])
... print(repr(data['text']))

>>> from zope.component import provideAdapter
>>> from zope.publisher.interfaces.browser import IBrowserRequest
Expand All @@ -60,7 +60,7 @@ Let's now look this up with some form data that is not encoded:

>>> from zope.interface import Interface, implements
>>> from zope.component import getMultiAdapter

>>> context = Bar()
>>> request = make_request(form={'form.widgets.text': 'foo'})

Expand Down
28 changes: 14 additions & 14 deletions src/plone/z3cform/layout.txt
Expand Up @@ -38,23 +38,23 @@ Then we create a simple form:
>>> from plone.z3cform.layout import FormWrapper

>>> class MySchema(interface.Interface):
... age = schema.Int(title=u"Age")
... age = schema.Int(title=u'Age')

>>> from z3c.form.interfaces import IFieldsForm
>>> from zope.interface import implements
>>> class MyForm(form.Form):
... implements(IFieldsForm)
... fields = field.Fields(MySchema)
... ignoreContext = True # don't use context to get widget data
... ignoreContext = True # don't use context to get widget data
...
... @button.buttonAndHandler(u'Apply')
... def handleApply(self, action):
... data, errors = self.extractData()
... print data['age'] # ... or do stuff
... print(data['age']) # ... or do stuff

>>> class MyFormWrapper(FormWrapper):
... form = MyForm
... label = u"Please enter your age"
... label = u'Please enter your age'

>>> from zope.component import provideAdapter
>>> from zope.publisher.interfaces.browser import IBrowserRequest
Expand All @@ -63,7 +63,7 @@ Then we create a simple form:
>>> provideAdapter(adapts=(Interface, IBrowserRequest),
... provides=Interface,
... factory=MyFormWrapper,
... name=u"test-form")
... name=u'test-form')

For our context, we define a class that inherits from Acquisition.
This is to satisfy permission checking later on, and it'll allow the
Expand All @@ -79,7 +79,7 @@ Let's verify that worked:
>>> from zope.component import getMultiAdapter
>>> context = Bar()
>>> request = make_request()
>>> getMultiAdapter((context, request), name=u"test-form")
>>> getMultiAdapter((context, request), name=u'test-form')
... # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
<MyFormWrapper object ...>

Expand All @@ -106,17 +106,17 @@ it returns. Normally, you'd register this view class using ZCML, like
with any other view.

>>> from plone.z3cform.layout import wrap_form
>>> view_class = wrap_form(MyForm, index=layout, label=u"My label")
>>> view_class = wrap_form(MyForm, index=layout, label=u'My label')
>>> provideAdapter(adapts=(Interface, IBrowserRequest),
... provides=Interface,
... factory=view_class,
... name=u"test-form2")
... name=u'test-form2')

Let's render this view:

>>> view = getMultiAdapter(
... (context, request), name=u"test-form2")
>>> print view() # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
... (context, request), name=u'test-form2')
>>> print(view()) # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
<html>Hello, this is your layout speaking:...My label...Age...</html>

If we don't pass the label to ``wrap_form``, it'll try to look up the
Expand All @@ -129,15 +129,15 @@ label from the form instance:

>>> view_class = wrap_form(MyLabelledForm, index=layout)
>>> view = view_class(context, request)
>>> print view() # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
>>> print(view()) # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
<html>Hello, this is your layout speaking:...Another label...Age...</html>


Send bad data to the form:

>>> request = make_request(form={'form.widgets.age': '12.1'})
>>> from zope.interface import Interface, implements
>>> formWrapper = getMultiAdapter((context, request), name=u"test-form")
>>> formWrapper = getMultiAdapter((context, request), name=u'test-form')
>>> form = formWrapper.form(context, request)
>>> form.update()
>>> data, errors = form.extractData()
Expand All @@ -151,7 +151,7 @@ And then send correct data to the form:
>>> request = make_request(form={'form.widgets.age': '12'})
>>> from zope.interface import Interface, implements
>>> from Acquisition import Implicit
>>> formWrapper = getMultiAdapter((context, request), name=u"test-form")
>>> formWrapper = getMultiAdapter((context, request), name=u'test-form')
>>> form = formWrapper.form(context, request)
>>> form.update()
>>> data, errors = form.extractData()
Expand All @@ -177,7 +177,7 @@ Note that the 'form' parameter here should be the wrapper view class, or an
interface implemented by it, not the form class itself.

>>> provideAdapter(layout_factory)
>>> print view() # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
>>> print(view()) # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
<html>Hello, this is your layout speaking:...Another label...Age...</html>

Clean up:
Expand Down
8 changes: 4 additions & 4 deletions src/plone/z3cform/traversal.txt
Expand Up @@ -46,7 +46,7 @@ First, we create a simple form and context.
... fields = field.Fields(MySchema)
...
... def update(self):
... print "Updating test form"
... print("Updating test form")
... super(MyForm, self).update()

>>> from zope.component import provideAdapter
Expand Down Expand Up @@ -115,7 +115,7 @@ contains some values for it.
... fields = field.Fields(MyListSchema)
...
... def update(self):
... print "Updating test form"
... print("Updating test form")
... super(MyListForm, self).update()

>>> provideAdapter(adapts=(Interface, IBrowserRequest),
Expand Down Expand Up @@ -184,7 +184,7 @@ Now create a schema that contains an object with a list of ages within it
... fields = field.Fields(MyParentSchema)
...
... def update(self):
... print "Updating test form"
... print("Updating test form")
... super(MyParentForm, self).update()

>>> provideAdapter(adapts=(Interface, IBrowserRequest),
Expand Down Expand Up @@ -275,7 +275,7 @@ Again, we create a simple form and context.
... ignoreContext = True # don't use context to get widget data
...
... def update(self):
... print "Updating test form"
... print("Updating test form")
... super(MyForm, self).update()

>>> class MyFormWrapper(FormWrapper):
Expand Down

0 comments on commit 417b17a

Please sign in to comment.