Example #1
0
def create_post_view(request, url_factory=url_factory):
    """url_factory arg only for testing purposes"""
    ## TODO: Factor me!!
    try:
        url = url_factory(request)
        response = Response(content_type='text/plain',
                            body=route_url('post', request, url))
    except NoURLSupplied:
        ## TODO: verify this is the right HTTP response.
        return HTTPPreconditionFailed("no url was supplied")
    except (HTTPNotFound, HTTPPreconditionFailed), e:
        return e
Example #2
0
def put_view(request, url_factory=url_factory):
    """Once again url_factory is only here for hooking in tests"""
    ## TODO: Factor me!!
    try:
        url = url_factory(request)
        location = route_url('put', request, url)
        response = HTTPCreated(location=location)
    except NoURLSupplied:
        ## TODO: verify this is the right HTTP response.
        response = HTTPPreconditionFailed("no url was supplied")
    except (HTTPNotFound, HTTPPreconditionFailed), e:
        response = e
Example #3
0
def create_post_view(request, url_factory=url_factory):
    """url_factory arg only for testing purposes"""
    ## TODO: Factor me!!
    try:
        url = url_factory(request)
        response = Response(content_type='text/plain',
                            body=route_url('post', request, url))
    except NoURLSupplied:
        ## TODO: verify this is the right HTTP response.
        return HTTPPreconditionFailed("no url was supplied")
    except (HTTPNotFound, HTTPPreconditionFailed), e:
        return e
    except URLAlreadyShorter, e:
        response = HTTPSeeOther(location=e.url)
    except HTTPFound, e:
        response = HTTPSeeOther(location=route_url('put', request, e.location))

    return response


@bfg_view(route_name='put')
def put_view(request, url_factory=url_factory):
    """Once again url_factory is only here for hooking in tests"""
    ## TODO: Factor me!!
    try:
        url = url_factory(request)
        location = route_url('put', request, url)
        response = HTTPCreated(location=location)
    except NoURLSupplied:
        ## TODO: verify this is the right HTTP response.
        response = HTTPPreconditionFailed("no url was supplied")