Created
May 22, 2010 21:29
-
-
Save maetl/410382 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PictureResource(ApiHandler): | |
def post(self, name, ext): | |
if not self.check_uploaded_picture(): | |
return | |
picture = Picture.find(name, ext) | |
if not picture: | |
picture = Picture() | |
picture.encode(self.request.POST['picture'], name, ext) | |
picture.caption = self.request.get('caption') | |
picture.save() | |
self.success_response(201, API_PICTURE_CREATED, picture.filename()) | |
else: | |
self.error_response(403, API_ERROR_EXISTS) | |
def put(self, name, ext): | |
if not self.check_uploaded_picture(): | |
return | |
picture = Picture.find(name, ext) | |
if picture: | |
picture = Picture() | |
picture.encode(self.request.POST['picture'], name, ext) | |
picture.caption = self.request.get('caption') | |
picture.save() | |
self.success_response(201, API_PICTURE_UPDATED, picture.filename()) | |
else: | |
self.error_response(404, API_ERROR_MISSING) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment