arag0rn
By: a guest | Dec 30th, 2008 | Syntax:
Python | Size: 1.17 KB | Hits: 168 | Expires: Never
import formencode
from paste.util.multidict import MultiDict
from formencode.variabledecode import variable_decode
from formencode import htmlfill
html = """
<input id="finish_date-1" type="text" value="" style="width: 80px;" name="finish_date"/>
<input id="finish_date-2" type="text" value="" style="width: 80px;" name="finish_date"/>
"""
html2="""<select name="finish_date">
<option value="aaa">
<option value="bbb">
<option value="">
</select>
"""
class DemoSchema(formencode.schema.Schema):
finish_date = formencode.foreach.ForEach(formencode.validators.DateConverter(month_style="dd/mm/yyyy"))
s = MultiDict ([('finish_date', 'aaa'), ('finish_date', 'bbb')])
print "---------------------- html 1 --------- "
try:
DemoSchema.to_python(s.mixed())
except formencode.Invalid, error:
print error.error_dict
print htmlfill.render( html,
defaults = variable_decode(s) )
print "---------------------- html 2 --------- "
try:
DemoSchema.to_python(s)
except formencode.Invalid, error:
print error.error_dict
print htmlfill.render( html2,
defaults = variable_decode(s) )