1. Jesper Noehr
  2. django-piston
  3. Issues
Issue #153 resolved

create() does not always return rc.CREATED

Daniel Graziotin
created an issue

{{{

class AnonymousPersonHandler(piston.handler.AnonymousBaseHandler): allowed_methods = ['POST'] model = server.models.Person fields = ('username','href')

# [...]

def create(self, request):
    attrs = self.flatten_dict(request.data)
    person = server.models.Person(**attrs)
    result = server.common.register(person)
    return result.value # contains an object of type Person

}}}

{{{

curl -H 'Content-Type:application/json' -X POST -d '{"username":"angelaasewsaweaa","password":"password","email":"rider@frideqwers.com","phone":"21w4fe4eeweff9294","gender":"M"}' http://127.0.0.1/api/persons/ -i

HTTP/1.1 200 OK Date: Wed, 01 Sep 2010 12:03:18 GMT Server: Apache/2.2.14 (Unix) mod_ssl/2.2.14 OpenSSL/0.9.8l DAV/2 mod_wsgi/4.0-TRUNK Python/2.6.1 Vary: Authorization,Cookie Content-Length: 90 Content-Type: application/json; charset=utf-8

[ "Person", { "username": "angelaasewsaweaa", "href": "http://127.0.0.1/api/persons/angela/" } ]

}}}

Comments (3)

  1. Log in to comment