class RestBookMarkView(BaseView): """ Json rest-api for expense bookmarks handling """ _schema = BookMarkSchema() @property def schema(self): return self._schema.bind(request=self.request) def get(self): """ Rest GET Method : get """ return get_bookmarks(self.request) def post(self): """ Rest POST method : add """ logger.debug(u"In the bookmark edition") appstruct = self.request.json_body try: bookmark = self.schema.deserialize(appstruct) except colander.Invalid, err: traceback.print_exc() logger.exception(" - Error in posting bookmark") logger.exception(appstruct) raise RestError(err.asdict(), 400) handler = BookMarkHandler(self.request) bookmark = handler.store(bookmark) return bookmark
def delete(self): """ Removes a bookmark """ logger.debug(u"In the bookmark deletion view") handler = BookMarkHandler(self.request) # Retrieving the id from the request id_ = self.request.matchdict.get('id') bookmark = handler.delete(id_) # if None is returned => there was no bookmark with this id if bookmark is None: raise RestError({}, 404) else: return dict(status="success")