Em Quarta 21 Junho 2006 12:22, Arthur Clune escreveu:
> I have a problem with unicode, or at least my understanding of how it
> works with validators.
>
> I have some code that looks like this in essence:
>
> In model.py:
>
>       class Ip(SQLObject):
>               ipaddr = StringCol(alternateID=True)

If you're using Unicode, this should be "UnicodeCol" instead of "StringCol". 

> In controllers.py I have a search page and a results page:
>
>      @expose(template="templates.ip_search")
>      def index(self):
>          """Basic IP search page"""
>          return dict(ip_search_form =  widgets.TableForm(fields=
> [ widgets.TextField("ipaddr") ], submit_text="Search"))
>
>      @expose(template="templates.ip_results")
>      @validate(validators={"ipaddr" : validators.String
> (not_empty=True)})

I prefer using "UnicodeString" as validator instead of "String". 

>      @turbogears.error_handler(index)
>      def results(self, ipaddr):
>          ip = Ip.byIp(ipaddr)
>       ... do stuff here....
>
> This fails with a unicode error
>
>      ip = Ip.byIp(ipaddr)
>    File "<string>", line 1, in <lambda>
>       [...]
> TypeError: argument 1 must be str, not unicode

Try using the UnicodeString validator and using a UnicodeCol instead. 

> If I add a ipaddr = str(ipaddr) line, all works fine, however I
> clearly don't understand something about validators since I thought
> validators.String() would do that conversion for me.

Actually it shouldn't.  UnicodeString validator should take care of that for 
you. 


-- 
Jorge Godoy      <[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
-~----------~----~----~----~------~----~------~--~---

Reply via email to