]>
Commit | Line | Data |
---|---|---|
1 | #!/usr/bin/python | |
2 | ||
3 | import tornado.web | |
4 | ||
5 | from handlers_base import * | |
6 | ||
7 | import backend | |
8 | ||
9 | from backend.databases import Databases | |
10 | ||
11 | class PlanetBaseHandler(BaseHandler): | |
12 | @property | |
13 | def db(self): | |
14 | return Databases().webapp | |
15 | ||
16 | @property | |
17 | def planet(self): | |
18 | return backend.Planet() | |
19 | ||
20 | ||
21 | class PlanetMainHandler(PlanetBaseHandler): | |
22 | rss_url = "/rss" | |
23 | ||
24 | def get(self): | |
25 | offset = int(self.get_argument("offset", 0)) | |
26 | limit = int(self.get_argument("limit", 4)) | |
27 | ||
28 | entries = self.planet.get_entries(offset=offset, limit=limit) | |
29 | ||
30 | self.render("planet/index.html", entries=entries, | |
31 | offset=offset + limit, limit=limit) | |
32 | ||
33 | ||
34 | class PlanetUserHandler(PlanetBaseHandler): | |
35 | def get(self, author): | |
36 | author = self.accounts.search(author) | |
37 | if not author: | |
38 | raise tornado.web.HTTPError(404, "User is unknown") | |
39 | ||
40 | offset = int(self.get_argument("offset", 0)) | |
41 | limit = int(self.get_argument("limit", 4)) | |
42 | ||
43 | entries = self.planet.get_entries_by_author(author.uid, | |
44 | offset=offset, limit=limit) | |
45 | ||
46 | self.render("planet/user.html", author=author, entries=entries, | |
47 | offset=offset + limit, limit=limit, rss_url="/user/%s/rss" % author.uid) | |
48 | ||
49 | ||
50 | class PlanetPostingHandler(PlanetBaseHandler): | |
51 | def get(self, slug): | |
52 | entry = self.planet.get_entry_by_slug(slug) | |
53 | ||
54 | if not entry: | |
55 | raise tornado.web.HTTPError(404) | |
56 | ||
57 | self.render("planet/posting.html", | |
58 | author=entry.author, entry=entry) |