def delete(self, id): try: story = Story.objects(id=id).first() story.delete() except Exception, e: logging.error(e) self.write({'errcode': 1, 'errmsg': 'del failed'})
def post(self, id): try: # self.guarantee('title', 'content', 'tags') # # story = Story(title=self.params.title, content=self.params.content) # story.tags = self.params.tags title = self.get_argument('title') content = self.get_argument('content') tags = self.get_argument('tags') story = Story(title=title, content=content) story.tags = list(tags) story.save() self.write({'errcode': 0, 'errmsg': 'success', 'data': story.to_json()}) except Exception, e: logging.error(e) self.write({'errcode': 1, 'errmsg': 'post failed'})
def put(self, id): try: story = Story.objects(id=id).first() story.title = self.get_argument('title') story.content = self.get_argument('content') story.tags = self.get_arguments('tags') story.update() self.write({'errcode': 0, 'errmsg': 'success', 'data': story.to_json()}) except Exception, e: logging.error(e) self.write({'errcode': 1, 'errmsg': 'put failed'})