Add hooks for pages to know more about their context

pull/2/head
Noah 2014-04-09 15:46:37 -07:00
parent c3052c302c
commit c9b9799589
2 changed files with 4 additions and 1 deletions

View File

@ -64,7 +64,7 @@ def before_request():
"author": "Noah Petherbridge", "author": "Noah Petherbridge",
"photo_url": config.PHOTO_ROOT_PUBLIC, "photo_url": config.PHOTO_ROOT_PUBLIC,
}, },
"uri": request.path.split("/")[1:], "uri": request.path,
"session": { "session": {
"login": False, # Not logged in, until proven otherwise. "login": False, # Not logged in, until proven otherwise.
"username": "guest", "username": "guest",

View File

@ -356,6 +356,7 @@ def partial_index():
selected = [] selected = []
stop = offset + BLOG_ENTRIES_PER_PAGE stop = offset + BLOG_ENTRIES_PER_PAGE
if stop > len(posts): stop = len(posts) if stop > len(posts): stop = len(posts)
index = 1 # Let each post know its position on-page.
for i in range(offset, stop): for i in range(offset, stop):
post_id = posts[i] post_id = posts[i]
post = Blog.get_entry(post_id) post = Blog.get_entry(post_id)
@ -375,6 +376,8 @@ def partial_index():
# Count the comments for this post # Count the comments for this post
post["comment_count"] = Comment.count_comments("blog-{}".format(post_id)) post["comment_count"] = Comment.count_comments("blog-{}".format(post_id))
post["position_index"] = index
index += 1
selected.append(post) selected.append(post)
g.info["count"] += 1 g.info["count"] += 1