def posts_id_delete(id): try: post = Post.get(id=id) except Post.DoesNotExist: return error('post does not exist', 404) if post.magazine_posts.count(): return error('存在关联的杂志引用,确定删除需要先删除关联的杂志引用') post.delete_instance() return ok()
def posts_public(id): try: post = Post.get(id=id) except Post.DoesNotExist: return error('post does not exist', 404) print(post.category) if post.category != 'source': post.update_visits() if post.category in ('recipe', 'recipe_list'): return redirect(post.content) else: return render_template('posts.html', post=post)
def posts_id_update(id): try: post = Post.get(id=id) except Post.DoesNotExist: return error('post does not exist', 404) json_data = request.get_json() author_name = json_data.get('author') category = json_data.get('category') title = json_data.get('title') content = json_data.get('content') if not all((author_name, category, title, content)): return error('没有提供所有参数') post.update_post(author_name=author_name, category=category, title=title, content=content) return ok()
def posts_id_update(id): try: post = Post.get(id=id) except Post.DoesNotExist: return error('post does not exist', 404) json_data = request.get_json() author_name = json_data.get('author') category = json_data.get('category') title = json_data.get('title') content = json_data.get('content') if not all((author_name, category, title, content)): return error('没有提供所有参数') post.update_post( author_name=author_name, category=category, title=title, content=content) return ok()
def posts_id(id): try: post = Post.get(id=id) except Post.DoesNotExist: return error('post does not exist', 404) return ok(dump_post(post))