Reorganized site and blog views and helpers to use LazyView

This increases the speed of the site by not requiring the site and blog code to
be imported on every request - just those that are relevant. It also splits the
code into modules which are easier to work with.
This commit is contained in:
str4d
2012-12-19 06:53:59 +00:00
parent 8f9e8fb178
commit 785f627d7a
5 changed files with 157 additions and 162 deletions

44
i2p2www/blog/views.py Normal file
View File

@ -0,0 +1,44 @@
from flask import request, abort, render_template
from werkzeug.contrib.atom import AtomFeed
from i2p2www import BLOG_ENTRIES_PER_PAGE
from i2p2www.blog.helpers import get_blog_entries, get_blog_feed_items, render_blog_entry
from i2p2www.helpers import Pagination, get_for_page
############
# Blog views
def blog_index(page):
all_entries = get_blog_entries()
entries = get_for_page(all_entries, page, BLOG_ENTRIES_PER_PAGE)
if not entries and page != 1:
abort(404)
pagination = Pagination(page, BLOG_ENTRIES_PER_PAGE, len(all_entries))
return render_template('blog/index.html', pagination=pagination, entries=entries)
def blog_entry(slug):
# try to render that blog entry.. throws 404 if it does not exist
parts = render_blog_entry(slug)
if parts:
# now just pass to simple template file and we are done
return render_template('blog/entry.html', parts=parts, title=parts['title'], body=parts['fragment'], slug=slug)
else:
abort(404)
def blog_rss():
# TODO: implement
pass
def blog_atom():
# TODO: Only output beginning of each blog entry
feed = AtomFeed('I2P Blog', feed_url=request.url, url=request.url_root)
items = get_blog_feed_items(10)
for item in items:
feed.add(item['title'],
item['content'],
content_type='html',
url=item['url'],
updated=item['updated'])
return feed.get_response()