def put(self, title): note = NoteModel.filter_by_title(title) data = Note.parser.parse_args() author = AuthorModel.filter_by_name(data['author']) if author is None: return {'message': 'This author is not registered yet'}, 404 if note is None: note = NoteModel(title, **data) else: Note.parser.add_argument('new_title', dest='title') data = Note.parser.parse_args() note.title = data['title'] note.author_id = author.id note.note = data['note'] note.updated_date = datetime.datetime.now() try: note.save_to_db() except Exception: return {'message': 'can not save the note'}, 500 return note.json(), 200
def post(self, title): if NoteModel.filter_by_title(title): return {"message": "note with that title already exists"}, 409 data = Note.parser.parse_args() author = AuthorModel.filter_by_name(data['author']) if author.id is None: return {'message': 'This author is not registered yet'}, 404 note = NoteModel(title, author.id, data['note']) try: note.save_to_db() except Exception: return {'message': 'can not save the note'}, 500 return note.json(), 201
def _author_json(name): author = AuthorModel.filter_by_name(name) return author.json()
def _author(name): return AuthorModel.filter_by_name(name)