Guest
Public paste!

arag0rn

By: a guest | Dec 30th, 2008 | Syntax: Python | Size: 1.17 KB | Hits: 168 | Expires: Never
Copy text to clipboard
  1. import formencode
  2. from paste.util.multidict import MultiDict
  3. from formencode.variabledecode import variable_decode
  4. from formencode import htmlfill
  5.  
  6. html = """
  7.         <input id="finish_date-1" type="text" value="" style="width: 80px;" name="finish_date"/>
  8.         <input id="finish_date-2" type="text" value="" style="width: 80px;" name="finish_date"/>       
  9. """
  10.  
  11. html2="""<select name="finish_date">
  12.   <option value="aaa">
  13.   <option value="bbb">
  14.   <option value="">
  15. </select>
  16. """
  17.  
  18.  
  19. class DemoSchema(formencode.schema.Schema):
  20.         finish_date = formencode.foreach.ForEach(formencode.validators.DateConverter(month_style="dd/mm/yyyy"))
  21.  
  22. s = MultiDict ([('finish_date', 'aaa'), ('finish_date', 'bbb')])
  23.  
  24.  
  25. print "---------------------- html 1 --------- "
  26. try:
  27.         DemoSchema.to_python(s.mixed())
  28. except formencode.Invalid, error:
  29.         print error.error_dict 
  30.         print htmlfill.render( html,
  31.                                defaults = variable_decode(s) )
  32.  
  33. print "---------------------- html 2 --------- "
  34.  
  35. try:
  36.         DemoSchema.to_python(s)
  37. except formencode.Invalid, error:
  38.         print error.error_dict 
  39.         print htmlfill.render( html2,
  40.                                defaults = variable_decode(s) )