On Fri, Jul 24, 2009 at 12:19 PM, David Broudy<[email protected]> wrote: > On Jul 24, 2009, at 4:20 AM, 一首诗 wrote: > > we have 2 choices: > > 1. don't use relationship of SA to use the default encode mechanism of > turbojson > 2. write a customized "__json__" > > I think, the 1st choice is not acceptable in most cases, but the 2nd > one is also annoying when we have more than 40 tables. > > > There's at least one other choice: Use the jsonify.when decorator. If you > can define your criteria using hasattr instead of isinstance, then this > should be less tedious than defining __json__ on every class. Sorry, I don't > have an example of this I can post, as it was easier in my case to just use > __json__ In fact, I'm not sure where the decorator is documented, but > looking at the source it's pretty obvious, and it's just a thin wrapper > of prioritized_methods.prioritized_when anyway. > Hope that helps.
That behavior is stripped in TG2.1 mainly because no one really used it. And getting rid of ruledispatch was a big deal. Currently the code has no alternative. Your solution for this problem could work with the "when" decorator but I don't see it as the best solution. Which criteria will you use to strip all unwanted attributes from all objects? It seems to me like a very big set of hasattr check that will return false on all objects that don't have it and only true on a flew that do. Wouldn't it be better to subclass the serializer and do things from there? again which will be the criteria? Will anyone come up with an example where this is needed? Back to the original point I seriously doubt you will need that many __json__ methods and I also doubt there is a generic way to serialize relationships that will make everyone happy. > Dave Broudy > Three Aspen Software > 2922 Evergreen Pkwy, Suite 311 > Evergreen, CO 80439 > Email: [email protected] // Web: http://www.threeaspen.com > Office: 303.278.0908 // Fax: 303.500.3112 > AIM/YIM: dbroudy > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---

