def new_post(): form = Edit_Post_Form() post = Post() form.category_id.choices = [(category.id, category.name) for category in Category.get_all_items()] if form.load_form_to_object(post, query="post"): post.add_itself() return redirect(post.url()) return render_template("edit_post.html", form=form)
def edit_post(post_id): if current_user.is_owner_or_admin(post_id): form = Edit_Post_Form() post = Post.get_item_by_id(post_id) form.category_id.choices = [(category.id, category.name) for category in Category.get_all_items()] post.tags_temp = ','.join(t.name for t in post.tags) form.load_object_to_form(post) if form.load_form_to_object(post, query='post'): return redirect(post.url()) return render_template("edit_post.html", form=form) else: # raise 403 Forbidden for insuficcient permissions abort(403)
def inject_category(): """Inject categories into context_processor """ from app.models import Category categories = Category.get_all_items() return dict(categories=categories)
def all_categories(): categories = Category.get_all_items() return render_template("all_categories.html", categories=categories)