]> git.ipfire.org Git - ipfire.org.git/blame - webapp/handlers_news.py
Move everything to the root of the repository.
[ipfire.org.git] / webapp / handlers_news.py
CommitLineData
940227cb
MT
1#!/usr/bin/python
2
3import tornado.web
4
5from handlers_base import *
6
940227cb 7class NewsIndexHandler(BaseHandler):
de683d7c
MT
8 rss_url = "/news.rss"
9
940227cb
MT
10 """
11 This handler fetches the content that is show on the news portal.
12 """
13 def get(self):
7771acea 14 news = self.news.get_latest(limit=5, locale=self.locale)
940227cb 15
7771acea 16 return self.render("news.html", news=news)
940227cb 17
7771acea
MT
18
19class NewsYearHandler(NewsIndexHandler):
20 def get(self, year):
21 news = self.news.get_by_year(year, locale=self.locale)
22
23 return self.render("news-year.html", news=news, selected_year=year)
940227cb
MT
24
25
26class NewsItemHandler(BaseHandler):
de683d7c
MT
27 rss_url = "/news.rss"
28
940227cb
MT
29 """
30 This handler displays a whole page full of a single news item.
31 """
32 def get(self, slug):
33 news = self.news.get_by_slug(slug)
34 if not news:
35 raise tornado.web.HTTPError(404)
36
37 # Find the name of the author
38 author = self.get_account(news.author_id)
39 if author:
40 news.author = author.cn
41 else:
42 _ = self.locale.translate
43 news.author = _("Unknown author")
44
45 return self.render("news-item.html", item=news)
46
47
48class NewsAuthorHandler(BaseHandler):
49 """
50 This page displays information about the news author.
51 """
52 def get(self, author):
53 author = self.get_account(author)
54 if not author:
55 raise tornado.web.HTTPError(404)
56
57 latest_news = self.news.get_latest(author=author.uid,
de683d7c 58 locale=self.locale, limit=10)
940227cb
MT
59
60 self.render("news-author.html",
61 author=author, latest_news=latest_news)