Ejemplo n.º 1
0
from jmoiron.utils import Page
from jmoiron.admin.models import Manager, Module

from models import *

admin = Manager(blueprint)

@admin.register("summary")
def summary():
    """Display a summary table of posts as the default dashboard view of the
    blog admin."""
    return comment_summary(count=5)

comment = Module("comment")

@comment.register("summary")
def comment_summary(count=10):
    comments = Comment.find().order_by("-timestamp")[:count]
    module = comment
    return render_template("comments/admin/comment_summary.html", **locals())

@comment.register("list")
def comment_list(count=25):
    page = Page(int(request.args.get('page', 1)), count, Comment.find().order_by("-timestamp").count())
    comments = Comment.find().order_by("-timestamp")[page.slice()]
    module = comment
    return render_template("comments/admin/comment_list.html", **locals())


admin.add_module(comment)
Ejemplo n.º 2
0
    module = post
    title = "Blog posts"
    subtitle = "latest first"
    return render_template("blog/admin/post_summary.html", **locals())


@post.register("list")
def post_list(count=20):
    page = Page(int(request.args.get('page', 1)), count, Post.find().count())
    posts = Post.find().order_by("-timestamp")[page.slice()]
    module = post
    title = "Blog posts"
    subtitle = "latest first"
    return render_template("blog/admin/post_list.html", **locals())


@post.register("edit")
def post_edit(id):
    module = post
    post_obj = Post.find_one({"id": int(id)})
    post_obj.load_comments()
    if not post:
        abort(404)
    form = PostForm(MultiDict(post_obj.items()))
    ctx = locals()
    ctx['post'] = post_obj
    return render_template("blog/admin/post_edit.html", **ctx)


admin.add_module(post)
Ejemplo n.º 3
0
    module = post
    title = "Blog posts"
    subtitle = "latest first"
    return render_template("blog/admin/post_summary.html", **locals())

@post.register("list")
def post_list(count=20):
    page = Page(int(request.args.get('page', 1)), count, Post.find().count())
    posts = Post.find().order_by("-timestamp")[page.slice()]
    module = post
    title = "Blog posts"
    subtitle = "latest first"
    return render_template("blog/admin/post_list.html", **locals())

@post.register("edit")
def post_edit(id):
    module = post
    post_obj = Post.find_one({"id": int(id)})
    post_obj.load_comments()
    if not post:
        abort(404)
    form = PostForm(MultiDict(post_obj.items()))
    ctx = locals()
    ctx['post'] = post_obj
    return render_template("blog/admin/post_edit.html", **ctx)

admin.add_module(post)