After quickstarting a project the json.py module contains some useful
default jsonifyers, for instance for User, Permission, etc. I often
find myself returning tg_errors in json for which a jsonifyer is
needed. This is what I currently use:

from formencode.api import Invalid
from turbojson.jsonify import jsonify

@jsonify.when( 'isinstance( obj, Invalid )' )
def jsonify_tg_errors( obj ):
    result = { }
    result['msg'] = obj.msg
    result['value'] = obj.value
    result['error_list'] = getattr( obj, 'error_list', None )
    result['error_dict'] = getattr( obj, 'error_dict', None )
    return result

It would be handy maybe for others too if this jsonifyer would be in
json.py just like User, Permission, etc by default.

Cheers,
Daniel

--~--~---------~--~----~------------~-------~--~----~
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?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to