Skip to content Skip to sidebar Skip to footer

Pyramid Traversal Http Put To Uri That Doesn't Exist

So I have a pyramid traversal app and I'd like to be able to PUT to URIs that don't exist. Is there a way to do this in the view config? So for example I have this @view_defaults(c

Solution 1:

This sounds like a separate class for Group objects with a Group context and an UndefinedGroup context. Most views work on Group, but you could have a special method responding to PUT requests for UndefinedGroup objects. Note that UndefinedGroup should not subclass Group.

@view_defaults(context=Group, renderer='json')
class GroupView(object):
    def __init__(self, request):
        self.request = request

    @view_config(request_method='GET')
    def get(self):
        # return information about the group

    @view_config(context=UndefinedGroup, request_method='PUT')
    def put_new(self):
        # create a Group from the UndefinedGroup

    @view_config(request_method='PUT')
    def put_overwrite(self):
        # overwrite the old group with a new one

Your traversal tree would then be responsible for creating an UndefinedGroup object if it cannot find a Group.

Post a Comment for "Pyramid Traversal Http Put To Uri That Doesn't Exist"