Great to see the docs getting updated all the time!  Hadn't checked
them in a while and a lot has been added.

One thing I'd love to see is a cookbook example of how to structure
urls (for both traversal and url route apps) and how to write views
for ajax requests.

I'm not sure I'm taking the correct approach, but it seems to work...

Below is an example I have of a view for an ajax toggle button to
'Follow' something (in my app it's a 'place').  Looking at it, it
looks pretty simple I suppose, but it took a while to figure out a
strategy that would work for me...I'm pretty new to Pyramid.  In the
beginning I wasn't even sure I should be writing a view to handle an
ajax request, and after that what to return, what renderer to use,
etc...


@view_config(name='follow', context='model.place.Place',
renderer='json')
class FollowPlaceView(PlaceView):
    def __call__(self):
        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)

        return { 'status': 'success'}

-- 
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.

Reply via email to