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.Usersinstance 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()
-------------------------------------------------
-raju
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
sqlobject-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss