Spot on , it solved the problem by calling encode in email.
I have not used validate before, It must be my syntax problem,
If I cut and paste your code I get the following error
Traceback (most recent call last):
File "start-tutorial.py", line 23, in ?
from tutorial.controllers import Root
File
"/home/ma2/raju/turbogear/tutorial1/tutorial/tutorial/controllers.py", line
15, in ?
class Users:
File
"/home/ma2/raju/turbogear/tutorial1/tutorial/tutorial/controllers.py", line
32, in Users
@expose()
NameError: name 'validate' is not defined
-------------------------------------------------------------
yes I have
from turbogears.validators import Email
At the top of the file.
--Raju
On 1/18/07, Alberto Valverde <[EMAIL PROTECTED]> wrote:
On Jan 18, 2007, at 8:13 PM, Raju Subban wrote:
> Under
> % tg-admin shell
> >>> try:
> ... user = model.User.byEmail("thisthat")
> ... except model.SQLObjectNotFound:
> ... print("User not found")
> ... else:
> ... print "user found"
> ...
> User not found
>
> works ok!!
>
> ------------------------------------------------------
> When in conrtollers.py the browser splits out the following ERROR!!
> 500 Internal error
>
> The server encountered an unexpected condition which prevented it
> from fulfilling the request.
>
> Page handler: <bound method Users.add of
> <tutorial.controllers.Users instance at 0xb6cec96c>>
> Traceback (most recent call last):
> File "/home/local_linux/lib/python2.4/site-packages/
> CherryPy-2.2.1-py2.4.egg/cherrypy/_cphttptools.py", line 105, in _run
> self.main()
> File "/home/local_linux/lib/python2.4/site-packages/
> CherryPy-2.2.1-py2.4.egg/cherrypy/_cphttptools.py", line 254, in main
> body = page_handler(*virtual_path, **self.params)
> File "<string>", line 3, in add
> File "/home/local_linux/lib/python2.4/site-packages/
> TurboGears-1.0-py2.4.egg/turbogears/controllers.py", line 334, in
> expose
> output = database.run_with_transaction(
> File "<string>", line 5, in run_with_transaction
> File "/home/local_linux/lib/python2.4/site-packages/
> TurboGears-1.0-py2.4.egg/turbogears/database.py", line 260, in so_rwt
> retval = func(*args, **kw)
> File "<string>", line 5, in _expose
> File "/home/local_linux/lib/python2.4/site-packages/
> TurboGears-1.0-py2.4.egg/turbogears/controllers.py", line 351, in
> <lambda>
> mapping, fragment, args, kw)))
> File "/home/local_linux/lib/python2.4/site-packages/
> TurboGears-1.0-py2.4.egg/turbogears/controllers.py", line 378, in
> _execute_func
> output = errorhandling.try_call(func, *args, **kw)
> File "/home/local_linux/lib/python2.4/site-packages/
> TurboGears-1.0-py2.4.egg/turbogears/errorhandling.py", line 73, in
> try_call
> return func(self, *args, **kw)
> File "/home/ma2/raju/turbogear/tutorial1/tutorial/tutorial/
> controllers.py", line 40, in add
> user = model.User.byEmail(email)
> File "<string>", line 1, in <lambda>
> File "/home/local_linux/lib/python2.4/site-packages/
> SQLObject-0.7.2-py2.4.egg/sqlobject/main.py", line 1276, in
> _SO_fetchAlternateID
> result, obj = cls._findAlternateID(name, dbName, value,
> connection)
> File "/home/local_linux/lib/python2.4/site-packages/
> SQLObject-0.7.2-py2.4.egg/sqlobject/main.py", line 1272, in
> _findAlternateID
> value), None
> File "/home/local_linux/lib/python2.4/site-packages/
> SQLObject-0.7.2-py2.4.egg/sqlobject/dbconnection.py", line 591, in
> _SO_selectOneAlt
> return self.queryOne("SELECT %s FROM %s WHERE %s = %s" %
> File "/home/local_linux/lib/python2.4/site-packages/
> SQLObject-0.7.2-py2.4.egg/sqlobject/dbconnection.py", line 761, in
> queryOne
> return self._dbConnection._queryOne(self._connection, s)
> File "/home/local_linux/lib/python2.4/site-packages/
> SQLObject-0.7.2-py2.4.egg/sqlobject/dbconnection.py", line 343, in
> _queryOne
> self._executeRetry(conn, c, s)
> File "/home/local_linux/lib/python2.4/site-packages/
> SQLObject-0.7.2-py2.4.egg/sqlobject/mysql/mysqlconnection.py", line
> 77, in _executeRetry
> myquery = unicode(query, self.encoding)
> TypeError: decoding Unicode is not supported
> ---------------------------------------------------
> Its simple turorial model
> class User(SQLObject):
> email = StringCol(length=100,alternateID=True)
> lists = MultipleJoin('List')
>
> class List(SQLObject):
> title = UnicodeCol(notNone=True)
> user = ForeignKey('User')
> items = MultipleJoin('Item')
>
> class Item(SQLObject):
> value = UnicodeCol(notNone=True)
> list = ForeignKey('List')
> ~
> -----------------------------------------------------
> Contoller
> ---------------------------------------------
> class Users:
> #http://localhost:8080/index
> @expose(template="tutorial.templates.users")
> def index(self):
> users = model.User.select()
> return dict(users=users)
>
> @expose(template="tutorial.templates.user")
> def add(self, email):
> # Remove extra spaces
> email = email.strip()
> # Remove null bytes (they can seriously screw up the database)
> email = email.replace('\x00', '')
> print email
> if email:
> try:
> user = model.User.byEmail(email)
> except model.SQLObjectNotFound:
> user = model.User(email=email)
> print("User %s added!" % email)
> else:
> print("User %s already exists!" % email)
> else:
> print("E-mail must be non-empty!")
> raise cherrypy.HTTPRedirect('index')
>
> I have left out the Root()
> It has users =Users()
> -------------------------------------------------
>
the email that gets into your controller method is an unicode object
(automatically decoded by TG). It seems sqlobject is choking with it.
Try encoding it to utf-8 to see if it works.... (BTW, shouldn't SO do
this automatically?)
email =email.encode('utf-8')
BTW, why aren't you using an Email validator to validate the email?
this could make your controller simpler:
from turbogears.validators import Email
@validate(validators={'email':Email})
@expose()
def add(self, email, tg_errors=None):
if tg_errors:
print tg_errors
else:
print "Good email! %s" % email
Alberto
>
--
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---