def admin_post_edit(post_id=None): if post_id: post = Post.get_post_by_id(post_id) success_message = app.config['POST_EDIT_SUCCEED'] else: post = Post() success_message = app.config['POST_ADD_SUCCEED'] form = PostEditForm(request.form, post) if request.form: if form.validate(): if Post.update_post(post, form): flash(success_message, 'success') return redirect(url_for(config.END_POINT_ADMIN_POST_EDIT, post_id=post.id)) else: flash(app.config['FORM_ERROR'], 'error') available_tags = list(app.config['post_tags'].keys()) return render_template('admin/post_edit.html', form=form, tags=available_tags)
def show_editor(post_id): d = mongo.db.posts.find_one(post_id) post = Post(bson=d) form = PostEditForm() return render_template('editor.html', post=post, form=form)