Hi there,

Following is code for json.py that seems to handle sqlalchemy classes
automatically (plain SA, guess it should also work on ActiveMapper
classes).

Could someone who knows SA better that me take a look and tell me if
they think I'm doing it wrong?

Arnar


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

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to