def edit_post(id): # Edit an article # GET reloads the article from the DB and creates the form # POST edits in DB article = model.get_article(int(id)) if request.method=='GET': return render_template('edit.html', article=article) elif request.method=='POST': model.edit_post(request.form['title'], request.form['abstract'], request.form['text'], request.form['tags'], article) return redirect(url_for('view_post', id=int(id)))
def edit_post(id): # Edit an article # GET reloads the article from the DB and creates the form # POST edits in DB article = model.get_article(int(id)) if request.method == 'GET': return render_template('edit.html', article=article) elif request.method == 'POST': model.edit_post(request.form['title'], request.form['abstract'], request.form['text'], request.form['tags'], article) return redirect(url_for('view_post', id=int(id)))
def process_edit(post_pk): form = forms.EditPostForm(request.form) if form.validate() == False: flash('All fields are required.') return render_template('url_for(edit_post)', post_pk = post_pk) else: content = form.new_content.data old_post = model.get_post_by_pk(post_pk) old_post.is_deleted = True model.edit_post(current_user.user_id,old_post.post_id,content,old_post.title,old_post.is_featured,old_post.version_id+1,old_post.comment_count) return redirect(url_for("show_blog",author_id=current_user.user_id))
def process_edit(post_pk): form = forms.EditPostForm(request.form) if form.validate() == False: flash('All fields are required.') return render_template('url_for(edit_post)', post_pk=post_pk) else: content = form.new_content.data old_post = model.get_post_by_pk(post_pk) old_post.is_deleted = True model.edit_post(current_user.user_id, old_post.post_id, content, old_post.title, old_post.is_featured, old_post.version_id + 1, old_post.comment_count) return redirect(url_for("show_blog", author_id=current_user.user_id))
def edit_post(): username = None user = None if 'username' in session: username = session['username'] user = model.get_user(username) safe = model.check_location(username) if request.method == 'GET': post_id = request.args.get('id') try: post = model.get_post(post_id) if not post.author == user.username: logging.debug("edit_post1: Found exception(User is not the author of the post)") return error("User is not the author of the post") if post.type == "Secret" and not safe: return error("User is not in safe location") except Exception as e: logging.debug("edit_post1: Found exception(%s)" % e) return error("Error: Could not load the post") return render_template('edit_post.html', current_user=user, post=post, safe=safe) new_content = request.form['content'] new_type = request.form['type'] post_id = request.form['id'] logging.debug("edit_post: Trying (%s, %s)" % (new_content, new_type)) if not new_content: flash("You need to introduce some content.", 'error') if (post.type == "Secret" or new_type == "Secret") and not safe: return error("User is not in safe location") return render_template('edit_post.html', current_user=user, post=post, safe=safe) try: post = model.get_post(post_id) if not post.author == user.username: logging.debug("edit_post1: Found exception(User is not the author of the post)") return error("User is not the author of the post") if post.type == "Secret" and not safe: return error("User is not in safe location") new_post = model.edit_post(post_id, new_content, new_type) except Exception as e: logging.debug("edit_post2: Found exception(%s)" % e) return error("Error: Could not edit the post") if new_post: flash("Succesfully edited post",) logging.debug("edit_post: Succesful (%s)" % (username)) else: flash("Could not edit post",) return redirect(url_for('home'))
def POST(self, post_id): if session.user == 'admin': post_id = int(post_id) post = model.view_post(post_id) f = form.post_add_form(post.id, post.name, post.address, post.username, post.password, post.tag) if not f.validates(): return render({'title': settings.SITE_NAME}).edit(f) else: r = model.edit_post(f) if r: return web.redirect("/edit/%d" % post_id) else: return render({'title': settings.SITE_NAME}).failed() else: return render({'title': settings.SITE_NAME}).notauth()
def edit_post(): if 'username' in session: username = session['username'] current_user = model.get_user(username) if request.method == 'GET': post_id = request.args.get('id') try: post = model.get_post(post_id) except Exception as e: logging.debug("edit_post1: Found exception(%s)" % e) return error(e) return render_template('edit_post.html', current_user=current_user, post=post) new_content = html.escape(request.form['content']) new_type = html.escape(request.form['type']) post_id = html.escape(request.form['id']) logging.debug("edit_post: Trying (%s, %s)" % (new_content, new_type)) if not new_content: flash("You need to introduce some content.", 'error') return render_template('edit_post.html', current_user=current_user, post=post) try: new_post = model.edit_post(post_id, new_content, new_type) except Exception as e: logging.debug("edit_post2: Found exception(%s)" % e) return error(e) if new_post: flash("Succesfully edited post", ) logging.debug("edit_post: Succesful (%s)" % (username)) else: flash("Could not edit post", ) return redirect(url_for('home'))
def edit_post(pid): if pid < 0 or pid >= model.post_len(): return 'post not found' model.edit_post(pid, request.json['body']) return str(pid)