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.