Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Howitz committed Aug 15, 2013
2 parents 5c6e278 + 3b95f49 commit ef4f3f3
Show file tree
Hide file tree
Showing 13 changed files with 174 additions and 45 deletions.
28 changes: 25 additions & 3 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,34 @@
CHANGES
=======

3.0.0a4 (unreleased)
--------------------
3.0.3 (unreleased)
------------------

- Nothing changed yet.


3.0.2 (2013-08-14)
------------------

- Fix unicode decode error in weird cases in checkbox.CheckboxWidget.update and radio.RadioWidget.update (eg: when term.value is an Plone Archetype ATFile)

3.0.1 (2013-06-25)
------------------

- The alpha slipped out as 3.0.0, removed ``ZODB-4.0.0dev.tar.gz``
to reduce damage

- Fixed a bug in ``widget.py`` ``def wrapCSSClass``


3.0 (2013-06-24)
----------------

- Only add the 'required' CSS class to widgets when they are in input mode.

- Added support for IDict Widget in MultiWidget.
- Catch bug where if a select value was set as from hidden input

- Catch bug where if a select value was set as from hidden input
or through a rest url as a single value, it won't error out
when trying to remove from ignored list. Probably not the 100%
right fix but it catches core dumps and is sane anyways.
Expand All @@ -21,6 +42,7 @@ CHANGES
--------------------

- Updated pt_BR translation.

- Fixed a bug where file input value was interpeted as UTF-8.


Expand Down
Binary file removed ZODB-4.0.0dev.tar.gz
Binary file not shown.
41 changes: 23 additions & 18 deletions bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
use the -c option to specify an alternate configuration file.
"""

import os, shutil, sys, tempfile
import os
import shutil
import sys
import tempfile

from optparse import OptionParser

tmpeggs = tempfile.mkdtemp()
Expand All @@ -31,8 +35,8 @@
Simply run this script in a directory containing a buildout.cfg, using the
Python that you want bin/buildout to use.
Note that by using --setup-source and --download-base to point to
local resources, you can keep this script from going over the network.
Note that by using --find-links to point to local resources, you can keep
this script from going over the network.
'''

parser = OptionParser(usage=usage)
Expand All @@ -48,23 +52,21 @@
"bootstrap and buildout will get the newest releases "
"even if they are alphas or betas."))
parser.add_option("-c", "--config-file",
help=("Specify the path to the buildout configuration "
"file to be used."))
help=("Specify the path to the buildout configuration "
"file to be used."))
parser.add_option("-f", "--find-links",
help=("Specify a URL to search for buildout releases"))
help=("Specify a URL to search for buildout releases"))


options, args = parser.parse_args()

######################################################################
# load/install distribute
# load/install setuptools

to_reload = False
try:
import pkg_resources, setuptools
if not hasattr(pkg_resources, '_distribute'):
to_reload = True
raise ImportError
import pkg_resources
import setuptools
except ImportError:
ez = {}

Expand All @@ -73,8 +75,10 @@
except ImportError:
from urllib2 import urlopen

exec(urlopen('http://python-distribute.org/distribute_setup.py').read(), ez)
setup_args = dict(to_dir=tmpeggs, download_delay=0, no_fake=True)
# XXX use a more permanent ez_setup.py URL when available.
exec(urlopen('https://bitbucket.org/pypa/setuptools/raw/0.7.2/ez_setup.py'
).read(), ez)
setup_args = dict(to_dir=tmpeggs, download_delay=0)
ez['use_setuptools'](**setup_args)

if to_reload:
Expand All @@ -89,7 +93,7 @@
######################################################################
# Install buildout

ws = pkg_resources.working_set
ws = pkg_resources.working_set

cmd = [sys.executable, '-c',
'from setuptools.command.easy_install import main; main()',
Expand All @@ -104,22 +108,23 @@
if find_links:
cmd.extend(['-f', find_links])

distribute_path = ws.find(
pkg_resources.Requirement.parse('distribute')).location
setuptools_path = ws.find(
pkg_resources.Requirement.parse('setuptools')).location

requirement = 'zc.buildout'
version = options.version
if version is None and not options.accept_buildout_test_releases:
# Figure out the most recent final version of zc.buildout.
import setuptools.package_index
_final_parts = '*final-', '*final'

def _final_version(parsed_version):
for part in parsed_version:
if (part[:1] == '*') and (part not in _final_parts):
return False
return True
index = setuptools.package_index.PackageIndex(
search_path=[distribute_path])
search_path=[setuptools_path])
if find_links:
index.add_find_links((find_links,))
req = pkg_resources.Requirement.parse(requirement)
Expand All @@ -142,7 +147,7 @@ def _final_version(parsed_version):
cmd.append(requirement)

import subprocess
if subprocess.call(cmd, env=dict(os.environ, PYTHONPATH=distribute_path)) != 0:
if subprocess.call(cmd, env=dict(os.environ, PYTHONPATH=setuptools_path)) != 0:
raise Exception(
"Failed to execute command:\n%s",
repr(cmd)[1:-1])
Expand Down
1 change: 0 additions & 1 deletion buildout.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ parts = test coverage-test coverage-report python docs
versions = versions

[versions]
ZODB = 4.0.0dev
lxml = 3.1.0
python-gettext = 2.1
sourcecodegen = 0.6.14
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def alltests():

setup(
name='z3c.form',
version='3.0.0a4.dev0',
version='3.0.3.dev0',
author="Stephan Richter, Roger Ineichen and the Zope Community",
author_email="zope-dev@zope.org",
description="An advanced form and widget framework for Zope 3",
Expand Down
3 changes: 2 additions & 1 deletion src/z3c/form/browser/checkbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ def update(self):
for count, term in enumerate(self.terms):
checked = self.isChecked(term)
id = '%s-%i' % (self.id, count)
label = util.toUnicode(term.value)
if zope.schema.interfaces.ITitledTokenizedTerm.providedBy(term):
label = translate(term.title, context=self.request,
default=term.title)
else:
label = util.toUnicode(term.value)
self.items.append(
{'id':id, 'name':self.name + ':list', 'value':term.token,
'label':label, 'checked':checked})
Expand Down
52 changes: 52 additions & 0 deletions src/z3c/form/browser/checkbox.txt
Original file line number Diff line number Diff line change
Expand Up @@ -257,3 +257,55 @@ Check HIDDEN_MODE:
class="single-checkbox-widget" value="selected" />
</span>


Term with non ascii __str__
---------------------------

Check if a term which __str__ returns non ascii string does not crash the update method

>>> from zope.interface.verify import verifyClass
>>> from z3c.form import interfaces
>>> from z3c.form.browser import checkbox
>>> from z3c.form.testing import TestRequest

>>> request = TestRequest()

>>> widget = checkbox.CheckBoxWidget(request)
>>> widget.id = 'widget-id'
>>> widget.name = 'widget.name'

>>> import zope.schema.interfaces
>>> from zope.schema.vocabulary import SimpleVocabulary,SimpleTerm
>>> import z3c.form.term
>>> class ObjWithNonAscii__str__:
... def __str__(self):
... return 'héhé!'
>>> class MyTerms(z3c.form.term.ChoiceTermsVocabulary):
... def __init__(self, context, request, form, field, widget):
... self.terms = SimpleVocabulary([
... SimpleTerm(ObjWithNonAscii__str__(), 'one', 'One'),
... SimpleTerm(ObjWithNonAscii__str__(), 'two', 'Two'),
... ])
>>> zope.component.provideAdapter(MyTerms,
... adapts=(zope.interface.Interface,
... interfaces.IFormLayer, zope.interface.Interface,
... zope.interface.Interface, interfaces.ICheckBoxWidget))
>>> widget.update()
>>> print(widget.render())
<html>
<body>
<span class="option">
<input class="checkbox-widget" id="widget-id-0" name="widget.name:list" type="checkbox" value="one">
<label for="widget-id-0">
<span class="label">One</span>
</label>
</span>
<span class="option">
<input class="checkbox-widget" id="widget-id-1" name="widget.name:list" type="checkbox" value="two">
<label for="widget-id-1">
<span class="label">Two</span>
</label>
</span>
<input name="widget.name-empty-marker" type="hidden" value="1">
</body>
</html>
3 changes: 2 additions & 1 deletion src/z3c/form/browser/radio.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ def update(self):
for count, term in enumerate(self.terms):
checked = self.isChecked(term)
id = '%s-%i' % (self.id, count)
label = util.toUnicode(term.value)
if zope.schema.interfaces.ITitledTokenizedTerm.providedBy(term):
label = translate(term.title, context=self.request,
default=term.title)
else:
label = util.toUnicode(term.value)
self.items.append(
{'id':id, 'name':self.name, 'value':term.token,
'label':label, 'checked':checked})
Expand Down
52 changes: 52 additions & 0 deletions src/z3c/form/browser/radio.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,55 @@ the value (which is used as a backup label) contains non-ASCII characters:

Note: The "\234" character is interpreted differently in Pytohn 2 and 3
here. (This is mostly due to changes int he SimpleVocabulary code.)

Term with non ascii __str__
---------------------------

Check if a term which __str__ returns non ascii string does not crash the update method

>>> request = TestRequest()
>>> widget = radio.RadioWidget(request)
>>> widget.id = 'widget-id'
>>> widget.name = 'widget.name'
>>> template = os.path.join(os.path.dirname(z3c.form.browser.__file__),
... 'radio_input.pt')
>>> factory = z3c.form.widget.WidgetTemplateFactory(template)
>>> zope.component.provideAdapter(factory,
... (zope.interface.Interface, IDefaultBrowserLayer, None, None, None),
... IPageTemplate, name='input')

>>> import zope.schema.interfaces
>>> from zope.schema.vocabulary import SimpleVocabulary,SimpleTerm
>>> import z3c.form.term
>>> class ObjWithNonAscii__str__:
... def __str__(self):
... return 'héhé!'
>>> class MyTerms(z3c.form.term.ChoiceTermsVocabulary):
... def __init__(self, context, request, form, field, widget):
... self.terms = SimpleVocabulary([
... SimpleTerm(ObjWithNonAscii__str__(), 'one', 'One'),
... SimpleTerm(ObjWithNonAscii__str__(), 'two', 'Two'),
... ])
>>> zope.component.provideAdapter(MyTerms,
... adapts=(zope.interface.Interface,
... interfaces.IFormLayer, zope.interface.Interface,
... zope.interface.Interface, interfaces.IRadioWidget))
>>> widget.update()
>>> print(widget.render())
<html>
<body>
<span class="option">
<label for="widget-id-0">
<input class="radio-widget" id="widget-id-0" name="widget.name" type="radio" value="one">
<span class="label">One</span>
</label>
</span>
<span class="option">
<label for="widget-id-1">
<input class="radio-widget" id="widget-id-1" name="widget.name" type="radio" value="two">
<span class="label">Two</span>
</label>
</span>
<input name="widget.name-empty-marker" type="hidden" value="1">
</body>
</html>
2 changes: 1 addition & 1 deletion src/z3c/form/browser/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
class WidgetLayoutSupport(object):
"""Widget layout support"""

def wrapCSSClass(self, klass, pattern='s(class)%'):
def wrapCSSClass(self, klass, pattern='%(class)s'):
"""Return a list of css class names wrapped with given pattern"""
if klass is not None and pattern is not None:
return [pattern % {'class': k} for k in klass.split()]
Expand Down
2 changes: 1 addition & 1 deletion src/z3c/form/converter.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1056,7 +1056,7 @@ If the list is empty, the missing value is returned:
True

Dict Multi Data Converter
--------------------
-------------------------

For multi widgets and fields that work with a dictionary of other basic types, a
separate data converter is required. Let's create a dict of integers field and
Expand Down
6 changes: 3 additions & 3 deletions src/z3c/form/form.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ examples:
>>> from z3c.form import testing
>>> testing.setupFormDefaults()

Note, since version 2.4.2 the IFomrLayer doesn't provide IBrowserRequest
anymore. This is usefull if you like to use z3c.form components for other
requets then the IBrowserRequest.
Note, since version 2.4.2 the IFormLayer doesn't provide IBrowserRequest
anymore. This is useful if you like to use z3c.form components for other
requests than the IBrowserRequest.

>>> from zope.publisher.interfaces.browser import IBrowserRequest
>>> import z3c.form.interfaces
Expand Down
Loading

0 comments on commit ef4f3f3

Please sign in to comment.