Hi Neil.
An example, using a form that i have build. How can I pass a accented
char to form and don't get a 'Internal Server Error'?
[]'s
- Walter
# -*- coding: utf-8 -*-
"""
Simplest WSGI app using Paste and ToscaWidgets
Based on script by James Gardner
"""
from pkg_resources import require
require('Paste', 'twForms >= 0.1a2dev_r2479')
import formencode
from pprint import pformat, pprint
from genshi.template import Context, MarkupTemplate
from genshi.output import DocType
from formencode import Invalid
from paste.wsgiwrappers import WSGIRequest
from toscawidgets.widgets.forms import calendars
from toscawidgets.api import retrieve_resources, WidgetsList
from toscawidgets.widgets.forms import TableForm,HiddenField,
TextField,SingleSelectField
class UsuarioToscaForm(TableForm):
class fields(WidgetsList):
id = HiddenField(default=0)
matricula = TextField(label_text = u'Matr�cula', validator =
formencode.validators.UnicodeString(not_empty=True))
cpf = TextField(label_text = 'CPF', validator =
formencode.validators.UnicodeString(not_empty=True))
nome = TextField(validator =
formencode.validators.UnicodeString(not_empty=True))
senha = HiddenField(label_text=u'Senha')#, validator =
formencode.validators.UnicodeString(not_empty=True))
data_admissao = calendars.CalendarDatePicker(label_text =
u'Data de Admiss�o', date_format='%d/%m/%Y',calendar_lang='pt')
tipo = SingleSelectField(validator =
formencode.validators.Int,
options=[(1,u'Funcion�rio'),(2,u'Gerente')])
template = MarkupTemplate("""\
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:py="http://genshi.edgewall.org/"
xmlns:xi="http://www.w3.org/2001/XInclude"
py:strip="">
<meta http-equiv="Content-type" content="text/html; charset=UTF-8" />
<head>
<py:with vars="resources = resources or dict(head=[])">
<link py:for="rsrc in resources['head']"
py:replace="rsrc.display()" />
</py:with>
<title py:content="title" />
</head>
<body>
<py:with vars="resources = resources or dict(bodytop=[],
bodybottom=[])">
<div py:for="rsrc in resources['bodytop']"
py:replace="rsrc.display()" />
${form.display(value)}
<div py:for="rsrc in resources['bodybottom']"
py:replace="rsrc.display()" />
</py:with>
</body>
</html>
""",encoding = 'utf-8')
myform = UsuarioToscaForm()
def app(environ, start_response):
start_response('200 OK', [('Content-type','text/html')])
ctx = Context(
value = Person(),
form = myform,
title = 'Simplest WSGI app using TGWidgets',
# send the resources needed for the form to the template so their links
# can be rendered.
# TGWidgetsMiddleware will take care of serving them.
resources = retrieve_resources(myform),
)
#print(dir(WSGIRequest))
#print(dir(environ))
ambiente = WSGIRequest(environ)
#ambiente.charset = 'utf8'
ambiente.decode_param_names = True
input_values =ambiente.params
#print(input_values)
if input_values:
try:
value = myform.validate(input_values)
pprint(value)
return ['<h1>Validated data:</h1><pre>%s</pre><a
href="./">Again</a>' %
pformat(value)
]
except Invalid, error:
print 'formencode error', unicode(error)
t = template.generate(ctx)
html = t.render(method='xhtml', doctype=DocType.XHTML)
return [html]
from toscawidgets.middleware import TGWidgetsMiddleware
from toscawidgets.mods.wsgi import WSGIHostFramework
# Stack needed middleware
app = TGWidgetsMiddleware(app, WSGIHostFramework, show_apache_config=True)
if __name__ == '__main__':
import paste.httpserver
import webbrowser
webbrowser.open_new('http://localhost:8000')
paste.httpserver.serve(app, port=8000, host='0.0.0.0')
On 7/30/07, Neil Blakey-Milner <[EMAIL PROTECTED]> wrote:
>
> On 7/30/07, Neil Blakey-Milner <[EMAIL PROTECTED]> wrote:
> > You can also read PEP 263 on how you can tell Python how to treat
> > string literals in the file as something other can ASCII.
>
> Oops, other _than_ ASCII. And this only changes how the string is
> converted from the file encoding into a string - it doesn't do
> anything magic about how that string can be converted into a Unicode
> string - you still need to specify the correct encodings and so forth.
>
> Neil
> --
> Neil Blakey-Milner
> http://nxsy.org/
> [EMAIL PROTECTED]
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" 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/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---