]> git.ipfire.org Git - people/shoehn/ipfire.org.git/blame - www/webapp/handlers_news.py
Add some extra space under a list.
[people/shoehn/ipfire.org.git] / www / webapp / handlers_news.py
CommitLineData
940227cb
MT
1#!/usr/bin/python
2
3import tornado.web
4
5from handlers_base import *
6
7class NewsRedirectHandler(BaseHandler):
8 """
9 This handler redirects (with a given slug) to news.ipfire.org.
10
11 We do not show full news items on the main page and so need a simple
12 way to redirect. Here it is.
13 """
14 def get(self, slug):
15 self.redirect("http://news.ipfire.org/news/%s" % slug)
16
17
18class NewsIndexHandler(BaseHandler):
19 """
20 This handler fetches the content that is show on the news portal.
21 """
22 def get(self):
23 offset = int(self.get_argument("offset", 0))
24 limit = int(self.get_argument("limit", 4))
25
26 news = self.news.get_latest(
27 locale=self.locale,
28 limit=limit,
29 offset=offset,
30 )
31
32 return self.render("news.html", news=news,
33 offset=offset + limit, limit=limit)
34
35
36class NewsItemHandler(BaseHandler):
37 """
38 This handler displays a whole page full of a single news item.
39 """
40 def get(self, slug):
41 news = self.news.get_by_slug(slug)
42 if not news:
43 raise tornado.web.HTTPError(404)
44
45 # Find the name of the author
46 author = self.get_account(news.author_id)
47 if author:
48 news.author = author.cn
49 else:
50 _ = self.locale.translate
51 news.author = _("Unknown author")
52
53 return self.render("news-item.html", item=news)
54
55
56class NewsAuthorHandler(BaseHandler):
57 """
58 This page displays information about the news author.
59 """
60 def get(self, author):
61 author = self.get_account(author)
62 if not author:
63 raise tornado.web.HTTPError(404)
64
65 latest_news = self.news.get_latest(author=author.uid,
66 locale=self.locale, limit=3)
67
68 self.render("news-author.html",
69 author=author, latest_news=latest_news)