[TurboGears] Re: JSON and SQLObject

2006-11-08 Thread Diez B. Roggisch

iain duncan schrieb:
 On Wed, 2006-08-11 at 02:43 -0400, Jorge Vargas wrote:
 On 11/7/06, chiangf [EMAIL PROTECTED] wrote:

 My question is whether there is any way to access myfk.secondname from
 javascript?

 you could also write a jsonify rule (see json.py) that will make your
 myTable objects fetch this info but be aware of what your doing
 because you may be pulling out half your db if there is a big join
 
 Could one use mochikits logging facilities to check on how much is being
 passed via JSON?

Certainly. But a json method can also be just called from the browser 
itself, or using wget. Then you have the data directly visible.

Diez

--~--~-~--~~~---~--~~
 You received this message because you are subscribed to the Google Groups 
TurboGears group.
To post to this group, send email to turbogears@googlegroups.com
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
-~--~~~~--~~--~--~---



[TurboGears] Re: JSON and SQLObject

2006-11-08 Thread Alberto Valverde


On Nov 7, 2006, at 10:08 PM, chiangf wrote:


 I have a page that requests for JSON output from controller, which
 returns a list of selectresults from an SQLObject.  My table looks
 something like this:

 class myTable(SQLObject):
   name = UnicodeCol()
   date = DateTimeCol()
   myfk = ForeignKey('SecondTable')

 class secondTable(SQLObject):
   secondname = UnicodeCol()

 I have no problem displaying the variables 'name' and 'date' but I
 can't seem to get myfk.  In python code, I'm able to access
 myfk.secondname and I want to do something similar in the javascript
 code.  I understand that myfk is kind of like a pointer to the other
 table object and perhaps javascript doesn't understand this.

 My question is whether there is any way to access myfk.secondname from
 javascript

Yes as long as myfk get's jsonified too. By default ForeignKeys are  
not jsonified because, as Jorge pointed out, you could end up pulling  
too much data if every existing join was carelesly performed. The  
jsonify rule could look something like:

from turbojson import jsonify

@jsonify.when(isinstance(obj, myTable))
def jsonify_myTable(next_method, obj):
# first get the output of the next most specific rule, that is,  
jsonify_sqlobject
output = next_method(obj)
# Now add the jsonified joined object
output['myfk'] = jsonify(obj.myfk)
return output

The resulting json should look something like:
{'name':'foo', 'date':'a_date', 'myfk':{'secondname':'bar', }}

so from JS you can do: data['myfk']['secondname']

Hope it helps,
Alberto

--~--~-~--~~~---~--~~
 You received this message because you are subscribed to the Google Groups 
TurboGears group.
To post to this group, send email to turbogears@googlegroups.com
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
-~--~~~~--~~--~--~---



[TurboGears] Re: JSON and SQLObject

2006-11-08 Thread chiangf

Thanks, I'm going to give it a try!


Frank


--~--~-~--~~~---~--~~
 You received this message because you are subscribed to the Google Groups 
TurboGears group.
To post to this group, send email to turbogears@googlegroups.com
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
-~--~~~~--~~--~--~---



[TurboGears] Re: JSON and SQLObject

2006-11-08 Thread Jason Chu
On Tue, 07 Nov 2006 22:55:29 -0800
iain duncan [EMAIL PROTECTED] wrote:

 
 On Wed, 2006-08-11 at 02:43 -0400, Jorge Vargas wrote:
  On 11/7/06, chiangf [EMAIL PROTECTED] wrote:
  
  
   My question is whether there is any way to access myfk.secondname
   from javascript?
  
  you could also write a jsonify rule (see json.py) that will make
  your myTable objects fetch this info but be aware of what your doing
  because you may be pulling out half your db if there is a big join
 
 Could one use mochikits logging facilities to check on how much is
 being passed via JSON?
 
 I love that logger Bob! =)
 
 Iain

If you're using firefox, I'd check out firebug
(http://www.joehewitt.com/software/firebug/).  It lets you inspect
XMLHttpRequests.

Jason


signature.asc
Description: PGP signature


[TurboGears] Re: JSON and SQLObject

2006-11-08 Thread Bob Ippolito

On 11/8/06, Jason Chu [EMAIL PROTECTED] wrote:
 On Tue, 07 Nov 2006 22:55:29 -0800
 iain duncan [EMAIL PROTECTED] wrote:

 
  On Wed, 2006-08-11 at 02:43 -0400, Jorge Vargas wrote:
   On 11/7/06, chiangf [EMAIL PROTECTED] wrote:
   
   
My question is whether there is any way to access myfk.secondname
from javascript?
   
   you could also write a jsonify rule (see json.py) that will make
   your myTable objects fetch this info but be aware of what your doing
   because you may be pulling out half your db if there is a big join
 
  Could one use mochikits logging facilities to check on how much is
  being passed via JSON?
 
  I love that logger Bob! =)
 
  Iain

 If you're using firefox, I'd check out firebug
 (http://www.joehewitt.com/software/firebug/).  It lets you inspect
 XMLHttpRequests.


It's also a console for MochiKit.Logging, and provides an interactive
JS interpreter among other things.

-bob

--~--~-~--~~~---~--~~
 You received this message because you are subscribed to the Google Groups 
TurboGears group.
To post to this group, send email to turbogears@googlegroups.com
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
-~--~~~~--~~--~--~---



[TurboGears] Re: JSON and SQLObject

2006-11-08 Thread iain duncan

On Wed, 2006-08-11 at 15:22 -0800, Bob Ippolito wrote:
 On 11/8/06, Jason Chu [EMAIL PROTECTED] wrote:
  On Tue, 07 Nov 2006 22:55:29 -0800
  iain duncan [EMAIL PROTECTED] wrote:
 
  
   On Wed, 2006-08-11 at 02:43 -0400, Jorge Vargas wrote:
On 11/7/06, chiangf [EMAIL PROTECTED] wrote:


 My question is whether there is any way to access myfk.secondname
 from javascript?

you could also write a jsonify rule (see json.py) that will make
your myTable objects fetch this info but be aware of what your doing
because you may be pulling out half your db if there is a big join
  
   Could one use mochikits logging facilities to check on how much is
   being passed via JSON?
  
   I love that logger Bob! =)
  
   Iain
 
  If you're using firefox, I'd check out firebug
  (http://www.joehewitt.com/software/firebug/).  It lets you inspect
  XMLHttpRequests.
 
 
 It's also a console for MochiKit.Logging, and provides an interactive
 JS interpreter among other things.

I use it all the time for javascript! Just hadn't used it yet with TG.
=)
Iain



--~--~-~--~~~---~--~~
 You received this message because you are subscribed to the Google Groups 
TurboGears group.
To post to this group, send email to turbogears@googlegroups.com
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
-~--~~~~--~~--~--~---



[TurboGears] Re: JSON and SQLObject

2006-11-07 Thread Jorge Godoy

chiangf [EMAIL PROTECTED] writes:

 My question is whether there is any way to access myfk.secondname from
 javascript?

No.  All you have is what you give as the output of your JSON exposed method.
You can pass the decoded result that you're willing to have there.

If this information will be needed only in some cases, it might be worth going
to the database again with the ID you already have and fetching it. 

It all depends on your design and how many hits you'll end up with on your
database. 

-- 
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 turbogears@googlegroups.com
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
-~--~~~~--~~--~--~---



[TurboGears] Re: JSON and SQLObject

2006-11-07 Thread Jorge Vargas

On 11/7/06, chiangf [EMAIL PROTECTED] wrote:


 My question is whether there is any way to access myfk.secondname from
 javascript?

you could also write a jsonify rule (see json.py) that will make your
myTable objects fetch this info but be aware of what your doing
because you may be pulling out half your db if there is a big join

--~--~-~--~~~---~--~~
 You received this message because you are subscribed to the Google Groups 
TurboGears group.
To post to this group, send email to turbogears@googlegroups.com
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
-~--~~~~--~~--~--~---



[TurboGears] Re: JSON and SQLObject

2006-11-07 Thread iain duncan

On Wed, 2006-08-11 at 02:43 -0400, Jorge Vargas wrote:
 On 11/7/06, chiangf [EMAIL PROTECTED] wrote:
 
 
  My question is whether there is any way to access myfk.secondname from
  javascript?
 
 you could also write a jsonify rule (see json.py) that will make your
 myTable objects fetch this info but be aware of what your doing
 because you may be pulling out half your db if there is a big join

Could one use mochikits logging facilities to check on how much is being
passed via JSON?

I love that logger Bob! =)

Iain



--~--~-~--~~~---~--~~
 You received this message because you are subscribed to the Google Groups 
TurboGears group.
To post to this group, send email to turbogears@googlegroups.com
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
-~--~~~~--~~--~--~---