Guest User

Untitled

a guest
May 23rd, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1.  
  2.  
  3.  
  4. class UserContainer(object):
  5. def POST(self, *args, **kwargs):
  6. """
  7. Allow the creation of a new User.
  8. """
  9. make_new_user()
  10.  
  11. def subresource(self, path_info):
  12. id = None
  13. if len(path_info) > 0:
  14. id = path_info.pop(0)
  15. return UserInstance(id)
  16.  
  17. class UserInstance(object):
  18. def __init__(self, id):
  19. try:
  20. self.id = int(id)
  21. except ValueError:
  22. raise cherrypy.HttpError(404)
  23.  
  24. # For all but PUT methods there MUSt be a valid user identified
  25. # by self.id
  26. if resource_does_not_exist(self.id) and cherrypy.request.method != 'PUT':
  27. raise cherrypy.HttpError(404)
  28.  
  29. def GET(self, *args, **kwargs):
  30. """
  31. Return the appropriate representation of the instance.
  32. """
  33. return user_representation(self.id)
  34.  
  35. def POST(self, *args, **kwargs):
  36. """
  37. Update the fields of the user instance.
  38. """
  39. edit_instance(self.id)
  40. return some_redirect(self.id)
  41.  
  42. def PUT(self, *args, **kwargs):
  43. """
  44. Create a new user with the specified id
  45. """
  46. if resource_exists(self.id):
  47. raise cherrypy.HttpError(405, "User exists, can't put new user here")
  48. else:
  49. make_new_user(self.id)
  50. return some_redirect(self.id)
  51.  
  52. def DELETE(self, *args, **kwargs):
  53. """
  54. Delete the user specified at the id.
  55. """
  56. delete_user(self.id)
  57. return some_redirect(self.id)
Add Comment
Please, Sign In to add comment