def topic_show(id): if post_store.get_by_id(id) is None: abort(404) else: return render_template("topic_show.html", post=post_store.get_by_id(id)) return redirect(url_for("home"))
def topic_edit(id): if request.method == "POST": post = post_store.get_by_id(int(id)) post.title = request.form["title"] post.subject = request.form["content"] post_store.update(post) return redirect(url_for("home")) else: return render_template("topic_edit.html", po=post_store.get_by_id(int(id)))
def topic_edit(id): if request.method == "POST": post = post_store.get_by_id(id) if post is not None: post.title = request.form['title'] post.content = request.form['content'] post_store.update(post) return render_template("topic_show.html", post=post_store.get_by_id(id)) return redirect(url_for("home")) else: if post_store.get_by_id(id) is None: return redirect(url_for("home")) return render_template("topic_edit.html", post=post_store.get_by_id(id))
def topic_update(id): updated_post = post_store.get_by_id(id) if updated_post is None: abort(404) if request.method == "POST": updated_post.title = request.form["title"] updated_post.content = request.form["content"] post_store.update(updated_post) return redirect(url_for("home")) else: updated_post = post_store.get_by_id(id) return render_template("topic_edit.html", post=updated_post)
def api_topic_update(id): request_data = request.get_json() updated_post = post_store.get_by_id(id) updated_post.title = request_data["title"] updated_post.content = request_data["content"] post_store.update(updated_post) return jsonify(updated_post.__dict__())
def show_api(id): post = post_store.get_by_id(id) try: result = jsonify(post.serialize()) except AttributeError: result = abort(404, f"Topic with id: {id} doesn't exist") return result
def topic_delete_api(id): try: post = post_store.get_by_id(id) post_store.delete(id) except ValueError: abort(400, "this id not found") return jsonify(post.__dict__)
def topic_show_api(id): post = post_store.get_by_id(id) try: result = jsonify(post.__dict__) except AttributeError: result = abort(404, "topic with id: {id} doesn't exist") return result
def topic_show_api(post_id): post_to_show = post_store.get_by_id(post_id) try: result = jsonify(post_to_show.as_dict()) except AttributeError: result = abort(404, "topic with id: {post_id} doesn't exist ") return result
def topic_show(id): post = post_store.get_by_id(id) if post is None: abort(404, "this id is not exist") if request.method == "POST": return redirect(url_for("home")) else: return render_template("topic_show.html", po=post)
def delete_api(id): post = post_store.get_by_id(id) try: post_store.delete(id) result = jsonify(post.serialize()) except ValueError: result = abort(404, f"Topic with id: {id} doesn't exist") return result
def topic_show(id): if request.method == "POST": print "back" return redirect(url_for("home")) else: return render_template("topic_show.html", po=post_store.get_by_id(int(id)))
def update(id): post = post_store.get_by_id(id) if post is None: abort(404) request_data = request.get_json() post.title = request_data["title"] post.body = request_data["body"] post_store.update(post) return jsonify(post.__dict__())
def topic_update_api(post_id): request_data = request.get_json() post_to_update = post_store.get_by_id(post_id) try: post_to_update.title = request_data["title"] post_to_update.content = request_data["content"] post_store.update(post_to_update) result = jsonify(post_to_update.__dict__()) except AttributeError: result = abort(404, "topic with id: {post_id} doesn't exist") return result
def topic_update(id): post = post_store.get_by_id(id) if post is None: abort(404) if request.method == "GET": return render_template("topic_update.html", post=post) if request.method == "POST": post.title = request.form["topictitle"] post.content = request.form["topicbody"] post_store.update(post) return redirect(url_for("home"))
def edit_topic(id): post = post_store.get_by_id(id) if post is None: abort(404, f"Topic with id: {id} doesn't exist.") if request.method == 'POST': post.title = request.form['title'] post.content = request.form['content'] post_store.update(post) return redirect(url_for('home')) else: return render_template("edit.html", post = post)
def topic_edit(id): post = post_store.get_by_id(id) if post is None: abort(404, "this id is not exist") if request.method == "POST": post.title = request.form["title"] post.topic = request.form["content"] post_store.update(post) return redirect(url_for("home")) else: return render_template("topic_edit.html", post=post)
def topic_edit(id): posts = post_store.get_all() found_post = [post for post in posts if post.id == id][0] if request.method == "POST": updated_post = post_store.get_by_id(id) updated_post.title = request.form["title"] updated_post.content = request.form["content"] post_store.update(updated_post) return redirect(url_for("home")) else: return render_template("topic_edit.html", post=found_post)
def topic_edit(post_id): post_to_edit = post_store.get_by_id(post_id) if request.method == "POST": post_to_edit.title = request.form["title"] post_to_edit.content = request.form["content"] return redirect(url_for("home")) else: title = post_to_edit.title content = post_to_edit.content return render_template("topic_add.html", title=title, content=content, post_id=post_id)
def api_topic_update(id): request_data = request.get_json() post = post_store.get_by_id(id) try: post.title = request_data["title"] post.content = request_data["content"] post_store.update(post) result = jsonify(post.__dict__()) except AttributeError: result = abort(404, f"topic with id: {id} doesn't exist") except KeyError: result = abort(400, "Couldn't parse the request data !") return result
def topic_edit(id): request_data = request.get_json() updated_post = post_store.get_by_id(id) try: updated_post.title = request_data["title"] updated_post.body = request_data["body"] post_store.update(updated_post) result = jsonify(updated_post.__dict__()) except AttributeError: result = abort(404, f"topic with id: {id} does not exist") except KeyError: result = abort(400, f"could not parse request data") return result
def edit_api(id): post = post_store.get_by_id(id) request_data = request.get_json() try: post.title = request_data['title'] post.content = request_data['content'] post_store.update(post) result = jsonify(post.serialize()) except AttributeError: result = abort(404, f"Topic with id: {id} doesn't exist") except KeyError: result = abort(400, f"Couldn't parse the request data !") return result
def topic_update_api(id): request_data = request.get_json() topic_to_update = post_store.get_by_id(id) try: topic_to_update.title = request_data["title"] topic_to_update.content = request_data["content"] post_store.update(topic_to_update) result = jsonify(topic_to_update.as_dict()) except AttributeError: result = abort(404, f"topic with id: {id} doesn't exist") except KeyError: result = abort(400, f"couldn't parse the request data") return result
def topic_delete(id): post = post_store.get_by_id(id) if post is None: abort(404) post_store.delete(id) return redirect(url_for("home"))
def topic_show(id): post = post_store.get_by_id(id) if post is None: abort(404) return render_template("topic_show.html", post=post)
def topic_show(id): post = post_store.get_by_id(id) if post is None: abort(404, "Couldn't find this topic id !") return render_template("show_posts.html", post=post)
def topic_show(post_id): post_to_show = post_store.get_by_id(post_id) title = post_to_show.title content = post_to_show.content return render_template("topic_show.html", title=title, content=content)
def topic_show(id): post = post_store.get_by_id(id) if post is None: abort(404, "couldnot find this topic") else: return render_template("topic_show.html", post=post)
def show_topic(id): post = post_store.get_by_id(id) if post is None: abort(404, f"Topic with id: {id} doesn't exist.") return render_template("show.html", post = post)
def api_topic_show(id): post = post_store.get_by_id(id) return jsonify(post.__dict__())