flavour/ssf — pull request #13 by ptressel (2012-03-26 00:36:46+00:00)
Title: Provide a convenience function for retrieving a json list of basic person info.

Url path is /pr/profile -- this returns a json list of dicts, one per person. Each dict has 3 key-values: "name", "bio", and "url". Name is assembled out of the person's first, middle, last names from pr_person. The function used for this is not localized. Url is the location of the profile image, pr_image.url, and is only supplied if the user had an image marked as a profile image. It is a complete url (i.e. includes protocol and server) if it was explicitly supplied by the user. If the user uploaded an image, the url is a path relative to the server's url -- it includes the application name (e.g. "eden"). This url should be prepended with the url of the server from which the data was fetched. If a user did not have a bio or image url, that entry's value will be "". Sample output:

[{"bio": null, "name": "John Doe", "picture": null}, {"bio": null, "name": "Mary Lamb", "picture": "/ssf/default/download/pr_image.image.ac2f478ef201e1b2.4a656c6c79666973682e6a7067.jpg"}, {"bio": "Sam's short bio", "name": "Sam Spade", "picture": null}, {"bio": "Ted's short bio", "name": "Ted Bear", "picture": null}, {"bio": "Liza's short bio", "name": "Liza Mona", "picture": "/ssf/default/download/pr_image.image.b6039ffab511bf34.50656e6775696e732e6a7067.jpg"}]

NB: Web2py doesn't seem to support the type of SQL query needed here, hence the raw query. IMO this form may be faster than a (functionally equivalent) inline table (also not supported by Web2py), as the query optimizer may give up on encountering an inline table generated by a subquery, and just execute that as a separate step (essentially doing a create view and then throwing it away). FYI, here's a discussion of the possibility of adding inline tables to Web2py. If this revives, we could mention this alternate form of query that avoids the inline table.

http://groups.google.com/group/web2py/browse_thread/thread/8d50fd87d0f2e233