Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class UserContainer(object):
- def POST(self, *args, **kwargs):
- """
- Allow the creation of a new User.
- """
- make_new_user()
- def subresource(self, path_info):
- id = None
- if len(path_info) > 0:
- id = path_info.pop(0)
- return UserInstance(id)
- class UserInstance(object):
- def __init__(self, id):
- try:
- self.id = int(id)
- except ValueError:
- raise cherrypy.HttpError(404)
- # For all but PUT methods there MUSt be a valid user identified
- # by self.id
- if resource_does_not_exist(self.id) and cherrypy.request.method != 'PUT':
- raise cherrypy.HttpError(404)
- def GET(self, *args, **kwargs):
- """
- Return the appropriate representation of the instance.
- """
- return user_representation(self.id)
- def POST(self, *args, **kwargs):
- """
- Update the fields of the user instance.
- """
- edit_instance(self.id)
- return some_redirect(self.id)
- def PUT(self, *args, **kwargs):
- """
- Create a new user with the specified id
- """
- if resource_exists(self.id):
- raise cherrypy.HttpError(405, "User exists, can't put new user here")
- else:
- make_new_user(self.id)
- return some_redirect(self.id)
- def DELETE(self, *args, **kwargs):
- """
- Delete the user specified at the id.
- """
- delete_user(self.id)
- return some_redirect(self.id)
Add Comment
Please, Sign In to add comment