>From Getting started:
"SQLObject-based objects cannot yet be directly serialized as JSON. In the
future, there will likely be a way to plug in your own code to take your
objects and produce sane JSON versions of them."
Is there any work done on that area? What about just converting SQLObject
to a dict. Something like this would do the trick:
def obj_to_dict(obj):
obj_dict = {}
for field in obj.sqlmeta.columns:
obj_dict[field] = getattr(obj, field)
return obj_dict
And then just jsonify the dict (I really don't know anything about JSON
and how is the process of jsonify an object, but I don't thinks this would
be difficult and I find it pretty useful).
What about SelectResult? Maybe this could be done to jsonify it:
def selectResult_to_list(select_result):
obj_list = []
for obj in select_result:
obj_list.append(obj_to_dict(obj))
return obj_list
This way, you can do things like this in the controller:
@turbogears.expose(template='someproject.templates.objectlist')
def something(self):
return dict(objects=SomeSQLObject.select())
and get a prety list of dicts representing the object in JSON format (and
still having a nice pythonic SelectResult of SQLObjects to use in the
template with no loose of functionality).
--
LUCA - Leandro Lucarella - JID: luca(en)lugmen.org.ar - Debian GNU/Linux
.------------------------------------------------------------------------,
\ GPG: 5F5A8D05 // F8CD F9A7 BF00 5431 4145 104C 949E BFB6 5F5A 8D05 /
'--------------------------------------------------------------------'
You look so tired-unhappy,
bring down the government,
they don't, they don't speak for us.