[Zope3-Users] z3c.form, german umlauts on buttons

Andreas Reuleaux reuleaux at web.de
Sat Sep 8 19:09:22 EDT 2007



It appears to me that I can't have german umlauts (or any other
non-ascii chars for that matter) on buttons, for example ("Ändern"
 - with A umlaut - ist german for "Change"):

    # -*- coding: utf-8 -*-

    ...

    class MyDisplayForm(form.Form):

      ...

      @button.buttonAndHandler(u'Ändern')
      def change(self, action):
	  self.request.response.redirect('edit')

tons of error msgs:

      ...
      File "/home/reuleaux/work/adrn/src/adrn/browser/views.py", line 489, in ?
	class MyDisplayForm(form.Form):
      File "/home/reuleaux/work/adrn/src/adrn/browser/views.py", line 491, in MyDisplayForm
	@button.buttonAndHandler(u'Ändern')
      File "/home/reuleaux/tmp/z3c.form/src/z3c/form/button.py", line 181, in buttonAndHandler
	f_locals['buttons'] += Buttons(button)
      File "/home/reuleaux/tmp/z3c.form/src/z3c/form/button.py", line 83, in __init__
	arg.__name__ = util.createId(arg.title)
      File "/home/reuleaux/tmp/z3c.form/src/z3c/form/util.py", line 33, in createId
	return name.encode('hex')
      File "encodings/hex_codec.py", line 24, in hex_encode
    zope.configuration.xmlconfig.ZopeXMLConfigurationError: File "/home/reuleaux/work/adrn/parts/adrbuch/site.zcml", line 4.0-4.42
	ZopeXMLConfigurationError: File "/home/reuleaux/work/adrn/src/adrn/app.zcml", line 86.2-86.28
	ZopeXMLConfigurationError: File "/home/reuleaux/work/adrn/src/adrn/configure.zcml", line 27.2-27.32
	ZopeXMLConfigurationError: File "/home/reuleaux/work/adrn/src/adrn/browser/configure.zcml", line 40.2-40.27
	ZopeXMLConfigurationError: File "/home/reuleaux/work/adrn/src/adrn/browser/av/configure.zcml", line 14.2
	UnicodeEncodeError: 'ascii' codec can't encode character u'\xc4' in position 0: ordinal not in range(128)

I get similar errors at runtime (when rendering the form) if I try to
change the title of an existing button:

    class AdrEditForm(form.EditForm):

	...

	buttons=form.EditForm.buttons
	# save changes
	buttons['apply'].title=u'Änderungen speichern'

this gives me:

    Traceback (most recent call last):
      File "/home/reuleaux/z3eggs/tmp-nK7Ng/zope.publisher-3.5.0a1.dev_r78838-py2.4.egg/zope/publisher/publish.py", line 133, in publish
      File "/home/reuleaux/z3eggs/tmp1LrliP/zope.app.publication-3.4.0a1_2-py2.4.egg/zope/app/publication/zopepublication.py", line 167, in callObject
      File "/home/reuleaux/z3eggs/tmp-nK7Ng/zope.publisher-3.5.0a1.dev_r78838-py2.4.egg/zope/publisher/publish.py", line 108, in mapply
       - __traceback_info__: <security proxied z3c.pagelet.zcml.AdrEdit instance at 0xb6d1928c>
      File "/home/reuleaux/z3eggs/tmp-nK7Ng/zope.publisher-3.5.0a1.dev_r78838-py2.4.egg/zope/publisher/publish.py", line 114, in debug_call
      File "/home/reuleaux/work/adrn/src/adrn/browser/views.py", line 636, in __call__
	self.update(**kw)
      File "/home/reuleaux/work/adrn/src/adrn/browser/views.py", line 692, in update
	self.form.update()
      File "/home/reuleaux/work/adrn/src/adrn/browser/views.py", line 334, in update
	super(AdrEditForm, self).update()
      File "/home/reuleaux/tmp/z3c.form/src/z3c/form/form.py", line 183, in update
	self.updateActions()
      File "/home/reuleaux/tmp/z3c.form/src/z3c/form/form.py", line 179, in updateActions
	self.actions.update()
      File "/home/reuleaux/tmp/z3c.form/src/z3c/form/button.py", line 229, in update
	buttonAction = zope.component.getMultiAdapter(
      File "/home/reuleaux/z3eggs/tmpxWsYeR/zope.component-3.4.0a1-py2.4.egg/zope/component/_api.py", line 101, in getMultiAdapter
      File "/home/reuleaux/z3eggs/tmpxWsYeR/zope.component-3.4.0a1-py2.4.egg/zope/component/_api.py", line 114, in queryMultiAdapter
      File "/home/reuleaux/z3eggs/tmpxWsYeR/zope.component-3.4.0a1-py2.4.egg/zope/component/registry.py", line 206, in queryMultiAdapter
      File "/home/reuleaux/z3eggs/tmpiBfeIG/zope.interface-3.4.0-py2.4-linux-i686.egg/zope/interface/adapter.py", line 482, in queryMultiAdapter
      File "/home/reuleaux/tmp/z3c.form/src/z3c/form/button.py", line 191, in __init__
	action.Action.__init__(self, request, field.title)
      File "/home/reuleaux/tmp/z3c.form/src/z3c/form/action.py", line 60, in __init__
	name = util.createId(title)
      File "/home/reuleaux/tmp/z3c.form/src/z3c/form/util.py", line 33, in createId
	return name.encode('hex')
      File "encodings/hex_codec.py", line 24, in hex_encode
      UnicodeEncodeError: 'ascii' codec can't encode character u'\xc4' in position 0: ordinal not in range(128)

Two points to note:

* I don't want to introduce i18n just for the buttons

      @button.buttonAndHandler(_(u'Change'))

  My app is german only and if I was to introduce i18n I would still
  make german the primary language and English the second,
  i. e. I would still want

      @button.buttonAndHandler(_(u'Ändern'))

* This caused me no problems in formlib, there I could do e. g.

      @action(u'Aendern')
      def aendern(self, action, data):
	  self.request.response.redirect('edit')

      actions[u'actions.aendern'].label=u'Ändern'


      @action(u'Loeschen')
      def loeschen(self, action, data):
	  ...

      actions[u'actions.loeschen'].label=u'Löschen'

  This is the last show stopper of z3c.form for me:
  I promise I will stop lamenting about features of formlib
  not found in z3c.form once I get this fixed.

Did I overlook something here - some easy workaround maybe?


-Andreas


More information about the Zope3-users mailing list