Dear list...

I'm learning how to use Formencode to validate the input of the HTML
forms I use. Unfortunatly I have some breakage that I don't know how to
fix.

My controller:

===================================================
class DhcpZoneForm(formencode.Schema):
    allow_extra_fields = True
    filter_extra_fields = True
    new_network = formencode.validators.URL(not_empty=True)

class DhcpController(BaseController):
    def new(self):
        return render_response('dhcp/new.mako')

    @validate(schema=DhcpZoneForm, form=u'new')
    def new_form(self):
        return Response('Your network is: %s' %
            self.form_result.get('new_network'))
===================================================

The Mako template is pretty straight forward. Just a HTML form that is
supposed to call the "new_form" action with text fields where one field
is "new_network".

Mako template:
===================================================
# -*- coding: utf-8 -*-
<%inherit file="/base.mako"/>

<h1>New DHCP zone</h1>

${ h.form(h.url_for(action='new_form')) }
<table>
<tr>
    <th>Network</th>
    <td>${ h.text_field('new_network') }</td>
</tr>
<tr>
    <th>Comment</th>
    <td>${ h.text_field('new_comment') }</td>
</tr>
<tr>
    <th>Standard Lease Time</th>
    <td>${ h.text_field('new_standard_lease') }</td>
</tr>
</tr>
<tr>
    <th>Maximum Lease Time</th>
    <td>${ h.text_field('new_maximum_lease') }</td>
</tr>
</table>
${ h.submit() }
</form>
===================================================

Now the error that I get is:

===================================================
File '<string>', line 1 in <lambda>
File '/var/lib/python-support/python2.4/pylons/decorators/__init__.py', line 
106 in wrapper
  response.content = [htmlfill.render(form_content, params, errors)]
File '/usr/lib/python2.4/site-packages/formencode/htmlfill.py', line 70 in 
render
  p.close()
File '/usr/lib/python2.4/site-packages/formencode/htmlfill.py', line 235 in 
close
  self._text = ''.join([
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 10: 
ordinal not in range(128) the form was passed in as an encoded string, but some 
data or error messages were unicode strings; the form should be passed in as a 
unicode string
===================================================

In the debug window I clicked on the '>>' to see which code broke:

===================================================
try:
    self._text = ''.join([
        t for t in self._content if not isinstance(t, tuple)])
except UnicodeDecodeError, e:>>  self._text = ''.join([
===================================================

So I thought it's the self._content that is not correctly encoded in
unicode and had it print in the debug window. Among many other lines I
also found parts like these:

===================================================
'<li class="navtitel">',
'Host-Eintr\xc3\xa4ge',
'</li>',
===================================================

This is a german text that means 'Host-Einträge'. Shouldn't that string
rather be u'Host-Einträge'? What have I missed? I told Mako to use UTF8:

config/environment.py:
===================================================
# The following template options are passed to your template engines
tmpl_options = {}
tmpl_options['mako.input_encoding'] = 'UTF-8'
tmpl_options['mako.output_encoding'] = 'UTF-8'
tmpl_options['mako.default_filters'] = ['decode.utf8']
===================================================

Help! :)

Kindly
 Christoph


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to