]>
git.ipfire.org Git - ipfire.org.git/blob - src/web/blog.py
6 import handlers_base
as base
8 from . import ui_modules
10 class IndexHandler(base
.BaseHandler
):
12 posts
= self
.planet
.get_entries(limit
=3)
14 self
.render("blog/index.html", posts
=posts
)
17 class AuthorHandler(base
.BaseHandler
):
19 author
= self
.accounts
.get_by_uid(uid
)
21 raise tornado
.web
.HTTPError(404, "User is unknown")
23 # Get all posts from this author
24 posts
= self
.planet
.get_entries_by_author(author
.uid
)
26 raise tornado
.web
.HTTPError(404, "User has no posts")
28 self
.render("blog/author.html", author
=author
, posts
=posts
)
31 class FeedHandler(base
.BaseHandler
):
33 cache_key
= "%s-%s" % (self
.request
.host
, self
.request
.path
)
35 # Get feed from cache if possible
36 feed
= self
.memcached
.get(cache_key
)
38 posts
= self
.planet
.get_entries(limit
=50)
41 feed
= self
.render_string("blog/feed.xml", posts
=posts
,
42 now
=email
.utils
.formatdate())
44 # Store in cache for 5min
45 self
.memcached
.set(cache_key
, feed
, 300)
47 # Set correct content type
48 self
.set_header("Content-Type", "application/rss+xml")
54 class PostHandler(base
.BaseHandler
):
56 entry
= self
.planet
.get_entry_by_slug(slug
)
58 raise tornado
.web
.HTTPError(404)
60 self
.render("blog/post.html", post
=entry
)
63 class SearchHandler(base
.BaseHandler
):
65 q
= self
.get_argument("q")
67 posts
= self
.planet
.search(q
)
69 raise tornado
.web
.HTTPError(404, "Nothing found")
71 self
.render("blog/search-results.html", q
=q
, posts
=posts
)
74 class PostModule(ui_modules
.UIModule
):
75 def render(self
, post
):
76 return self
.render_string("blog/modules/post.html", post
=post
)
79 class PostsModule(ui_modules
.UIModule
):
80 def render(self
, posts
):
81 return self
.render_string("blog/modules/posts.html", posts
=posts
)