def GET(self): i = web.input(page=1) try: page = int(i.page) except: page = 1 context = {"page": page} query = web.ctx.orm.query(Post).filter(Post.content_type == "post") if i.get("status", ""): query = query.filter(Post.status == i.status) context["status"] = i.status post_count = query.count() posts = query.order_by("posts.created DESC").all() page_count = max(post_count / ADMIN_POST_PER_PAGE, 0) if post_count % ADMIN_POST_PER_PAGE > 0: # for not same page_count += 1 context["posts"] = posts[(page - 1) * ADMIN_POST_PER_PAGE : ADMIN_POST_PER_PAGE * page] context["all_count"] = self.all_count() context["page_count"] = page_count context["publish_count"] = self.pub_count() context["draft_count"] = web.ctx.orm.query(Post).filter(Post.status == "draft").count() context["categories"] = web.ctx.orm.query(Term).filter(Term.type == "category").all() context["archives"] = archives() return admin_render.posts(**context)
def get_sidebar(): return { 'page' : sidebar.pages(), 'category' : sidebar.categories(), 'tags' : sidebar.tags(), 'links' : sidebar.links(), 'recentcomments': sidebar.recentcomments(), 'archives' : sidebar.archives() }
def GET(self): i = web.input(page=1) try: page = int(i.page) except: page = 1 context = {} context["page"] = page query = web.ctx.orm.query(Post).filter(Post.content_type == "post") if i.get("status", ""): query = query.filter(Post.status == i.status) context["status"] = i.status if i.get("year", "") and i.get("month", ""): query = query.filter(extract("year", Post.created) == int(i.year)).filter( extract("month", Post.created) == int(i.month) ) category = i.get("category", "") # filter by category if category: query = query.filter(Post.terms.any(id=int(category))) posts = query.order_by("posts.created DESC").all() post_count = len(posts) if post_count != 0 and post_count % ADMIN_POST_PER_PAGE == 0: page_count = post_count / ADMIN_POST_PER_PAGE else: page_count = post_count / ADMIN_POST_PER_PAGE + 1 if page < 1 or page > page_count: raise web.notfound() context["posts"] = posts[(page - 1) * ADMIN_POST_PER_PAGE : page * ADMIN_POST_PER_PAGE] context["page_count"] = page_count context["all_count"] = self.all_count() context["publish_count"] = self.pub_count() context["draft_count"] = context["all_count"] - context["publish_count"] context["categories"] = web.ctx.orm.query(Term).filter(Term.type == "category").all() context["archives"] = archives() return admin_render.posts(**context)