#1052: jsonify for SQLAlchemy mapped objects
-------------------------+--------------------------------------------------
 Reporter:  Arnar        |       Owner:  anonymous
     Type:  enhancement  |      Status:  new      
 Priority:  normal       |   Milestone:           
Component:  TurboGears   |     Version:  0.9a6    
 Severity:  normal       |    Keywords:           
-------------------------+--------------------------------------------------
 The following jsonify-methods seem to work for SA-mapped objects.

 {{{
 #!python
 from turbojson.jsonify import jsonify

 import sqlalchemy

 @jsonify.when("isinstance(obj, sqlalchemy.attributes.InstrumentedList)")
 def jsonify_salist(obj):
    return list(obj)

 @jsonify.when("hasattr(obj, 'c') and isinstance(obj.c,
 sqlalchemy.util.OrderedProperties)")
 def jsonify_saobject(obj):
    props = {}
    for key in obj.c.keys():
        props[key] = getattr(obj, key)
    return props
 }}}

-- 
Ticket URL: <http://trac.turbogears.org/turbogears/ticket/1052>
TurboGears <http://www.turbogears.org/>
TurboGears front-to-back web development
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears Tickets" 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-tickets
-~----------~----~----~----~------~----~------~--~---

Reply via email to