Hello people!, I'm having trouble with singlejoin and SO. Nothing too
complicated, just doing an example to see how to use TG.
The example that fails on me is this one...
The idea is that One user can have One Pet. So it's a one-to-one
relationship. As far as I know its a singleJoin.
The thing is that when I'm using catwalk to insert my data, suddendly,
the insert user tab stops responding...I look at the logs and this is
what I see.
//
---------------------------------------------------------------------------------------------
2006-11-01 10:18:40,329 turbogears.identity INFO Identity is
available...
127.0.0.1 - - [01/Nov/2006:10:18:40] "GET
/catwalk/browse?object_name=User HTTP/1.1" 302 161 "" "Mozilla/5.0
(X11; U; Linux i686; en-US; rv:1.8.0.7) Gecko/20060921
Ubuntu/dapper-security Firefox/1.5.0.7"
2006-11-01 10:18:40,342 turbogears.identity DEBUG Retrieving identity
for visit: 68e36dab0194b37f098561b44aad3285d637c9d6
2006-11-01 10:18:40,343 turbogears.identity INFO Identity is
available...
2006-11-01 10:18:40,344 turbogears.database DEBUG Starting SQLObject
transaction
2006-11-01 10:18:40,346 turbogears.controllers DEBUG Calling <function
index at 0xb745d614> with *((<turbogears.toolbox.catwalk.browse.Browse
object at 0xb7467e6c>, u'User')), **({'start': 0, 'filters': '',
'context': '', 'page_size': 10})
01/Nov/2006:10:18:40 HTTP INFO Page handler: <bound method Browse.index
of <turbogears.toolbox.catwalk.browse.Browse object at 0xb7467e6c>>
Traceback (most recent call last):
File
"/usr/lib/python2.4/site-packages/CherryPy-2.2.1-py2.4.egg/cherrypy/_cphttptools.py",
line 105, in _run
self.main()
File
"/usr/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 index
File
"/usr/lib/python2.4/site-packages/TurboGears-1.0b1-py2.4.egg/turbogears/controllers.py",
line 326, in expose
output = database.run_with_transaction(
File "<string>", line 5, in run_with_transaction
File
"/usr/lib/python2.4/site-packages/TurboGears-1.0b1-py2.4.egg/turbogears/database.py",
line 246, in so_rwt
retval = func(*args, **kw)
File "<string>", line 5, in _expose
File
"/usr/lib/python2.4/site-packages/TurboGears-1.0b1-py2.4.egg/turbogears/controllers.py",
line 343, in <lambda>
mapping, fragment, args, kw)))
File
"/usr/lib/python2.4/site-packages/TurboGears-1.0b1-py2.4.egg/turbogears/controllers.py",
line 367, in _execute_func
output = errorhandling.try_call(func, *args, **kw)
File
"/usr/lib/python2.4/site-packages/TurboGears-1.0b1-py2.4.egg/turbogears/errorhandling.py",
line 71, in try_call
return func(self, *args, **kw)
File
"/usr/lib/python2.4/site-packages/TurboGears-1.0b1-py2.4.egg/turbogears/toolbox/catwalk/browse.py",
line 24, in index
total,rows =
self.rows_for_model(object_name,start,page_size,filters)
File
"/usr/lib/python2.4/site-packages/TurboGears-1.0b1-py2.4.egg/turbogears/toolbox/catwalk/browse.py",
line 124, in rows_for_model
relations = self.relation_values(object_name,rows)
File
"/usr/lib/python2.4/site-packages/TurboGears-1.0b1-py2.4.egg/turbogears/toolbox/catwalk/browse.py",
line 166, in relation_values
where=AND(
File
"/usr/lib/python2.4/site-packages/TurboGears-1.0b1-py2.4.egg/turbogears/toolbox/catwalk/browse.py",
line 196, in join_foreign_key
return getattr(column.otherClass.q,foreign_key)
File
"/usr/lib/python2.4/site-packages/SQLObject-0.7.1dev_r1860-py2.4.egg/sqlobject/sqlbuilder.py",
line 356, in __getattr__
raise AttributeError("%s instance has no attribute '%s'" %
(self.soClass.__name__, attr))
AttributeError: Pet instance has no attribute 'userID'
Request Headers:
COOKIE: tg-visit=68e36dab0194b37f098561b44aad3285d637c9d6
Content-Length:
ACCEPT-CHARSET: ISO-8859-1,utf-8;q=0.7,*;q=0.7
USER-AGENT: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.7)
Gecko/20060921 Ubuntu/dapper-security Firefox/1.5.0.7
CONNECTION: keep-alive
HOST: localhost:7654
ACCEPT:
text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Remote-Addr: 127.0.0.1
ACCEPT-LANGUAGE: en-us,en;q=0.5
Content-Type:
Remote-Host: 127.0.0.1
ACCEPT-ENCODING: gzip,deflate
KEEP-ALIVE: 300
127.0.0.1 - - [01/Nov/2006:10:18:40] "GET
/catwalk/browse/?object_name=User HTTP/1.1" 500 3182 "" "Mozilla/5.0
(X11; U; Linux i686; en-US; rv:1.8.0.7) Gecko/20060921
Ubuntu/dapper-security Firefox/1.5.0.7"
//
---------------------------------------------------------------------------------------------
the most important thing that I can see is this line:
################
raise AttributeError("%s instance has no attribute '%s'" %
(self.soClass.__name__, attr))
AttributeError: Pet instance has no attribute 'userID'
################
and I just don't get it... :(
models.py
//
------------------------------------------------------------------------------------------------------
from datetime import datetime
from sqlobject import *
from turbogears import identity
from turbogears.database import PackageHub
hub = PackageHub("singlejoin")
__connection__ = hub
# class YourDataClass(SQLObject):
# pass
class Pet(SQLObject):
class sqlmeta:
table = 'tg_pet'
name = UnicodeCol(length = 40)
surname = UnicodeCol(length = 40)
color = UnicodeCol(length = 40)
userid = ForeignKey("User")
class User(SQLObject):
"""
Reasonably basic User definition. Probably would want additional
attributes.
"""
# names like "Group", "Order" and "User" are reserved words in SQL
# so we set the name to something safe for SQL
class sqlmeta:
table = "tg_user"
user_name = UnicodeCol(length=16, alternateID=True,
alternateMethodName="by_user_name")
email_address = UnicodeCol(length=255, alternateID=True,
alternateMethodName="by_email_address")
display_name = UnicodeCol(length=255)
password = UnicodeCol(length=40)
created = DateTimeCol(default=datetime.now)
myPet = SingleJoin("Pet", joinColumn = "user_id")
# groups this user belongs to
groups = RelatedJoin("Group", intermediateTable="user_group",
joinColumn="user_id", otherColumn="group_id")
def _get_permissions(self):
perms = set()
for g in self.groups:
perms = perms | set(g.permissions)
return perms
def _set_password(self, cleartext_password):
"Runs cleartext_password through the hash algorithm before
saving."
hash = identity.encrypt_password(cleartext_password)
self._SO_set_password(hash)
def set_password_raw(self, password):
"Saves the password as-is to the database."
self._SO_set_password(password)
//
------------------------------------------------------------------------------------------------------
so...does anybody know whats wrong with this?
thanx!!
--
miya
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---