Thanks for the response... I'm using Pyramid with traversal for view lookup. It works well because I always have a context (in my case this is usually the db model object that the ajax request is done on), which is very handy. Because of this I'm not sure I want to have a specific url (eg: api- internal) from my ajax requests, but it's something to consider. I could set it up so traversal would work with these special urls.
Also, I saw some updates to the docs and did find this: http://docs.pylonsproject.org/projects/pyramid_tutorials/en/latest/humans/creatingux/step09/index.html step 9 specifically talks about ajax, but could be a bit more detailed. I really like the creatingux tutorial though! Answers tons of questions I had when first starting out. Wish I'd seen this a few months ago. On Jan 11, 12:11 pm, Jonathan Vanasco <[email protected]> wrote: > As a matter of preference, I like to treat ajax in my pylons/pyramid > apps in a very structured and repeatable way... > > 1. everything hits /api-public/versionX or /api-internal > 2. i use a standard response object / formatting > 3. i wrap everything in a try/except > 4. i commit/rollback > > the return value i always use defaults to > {'status':'error'} > > if i have issues, i'll trigger a custom error and populate the rval > for json display / js logging during debugging > {'status':'error', 'error':'no database connection'} > > if i have a success, i might return additional data in the json object > too > > i use pylons style handlers, so my methods and classes are structured > differently than yours. the general idea though is... > > ## global helpers > > def json_rval(): > return {'status':'error'} > > ## rendering method > > def method(self): > rval= json_rval() > try: > user = get_user_by_id(authenticated_userid(self.request)) > toggle_on = False > if 'toggle_on' in self.request.params: > toggle_on = self.request.params['toggle_on'] > if toggle_on: > user.follow(self.context) > else: > user.unfollow(self.context) > rval['status']= 'success' > db.commit() > > except: > rval['error']= 'based on the exception' > db.rollback() > > return rval -- You received this message because you are subscribed to the Google Groups "pylons-discuss" 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/pylons-discuss?hl=en.
