Exemplo n.º 1
0
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)
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
 def inject_category():
     """Inject categories into context_processor
     """
     from app.models import Category
     categories = Category.get_all_items()
     return dict(categories=categories)
Exemplo n.º 4
0
def all_categories():
    categories = Category.get_all_items()
    return render_template("all_categories.html", categories=categories)