1 |
1 |
2 class Page (object) : |
2 """ |
|
3 Handling page requests |
|
4 """ |
|
5 |
|
6 def handle_html (env) : |
|
7 return "A HTML page" |
|
8 |
|
9 |
|
10 # list of page handlers, by type |
|
11 type_handlers = [ |
|
12 ('.html', handle_html), |
|
13 ] |
|
14 |
|
15 def lookup_handler (path) : |
3 """ |
16 """ |
4 A page is kind of like a controller, I guess |
17 Look up and return a handler for the given page, or raise an error |
5 """ |
18 """ |
6 |
19 |
7 # the page title, used in the HTML <title> |
20 return handle_html |
8 title = None |
|
9 |
21 |
10 # the page name, used in the menu |
|
11 name = None |
|
12 |
|
13 # the page path, used in the URL |
|
14 path = None |
|
15 |
|
16 # parent page, can be self |
|
17 parent = None |
|
18 |
|
19 # menu of sub-pages, may be empty |
|
20 menu = None |
|
21 |
|
22 def __init__ (self, req, path_suffix) : |
|
23 self.req = req |
|
24 self.path_suffix = path_suffix |
|
25 |
|
26 # default parent to root |
|
27 if not self.parent : |
|
28 from pages import index as index_page |
|
29 |
|
30 self.parent = index_page.Page |
|
31 |
|
32 def _build_template (self, template_class) : |
|
33 tpl = template_class(searchList=[self.req]) |
|
34 |
|
35 tpl.page_title = self.title |
|
36 tpl.page_name = self.name |
|
37 tpl.page_path = self.path |
|
38 |
|
39 tpl.page_menu = self.menu |
|
40 tpl.page = self |
|
41 |
|
42 return tpl |
|
43 |
|
44 def get_response_code (self) : |
|
45 """ |
|
46 Returns the HTTP response code to be used |
|
47 """ |
|
48 |
|
49 return 200 |
|
50 |
|
51 def render_template (self) : |
|
52 """ |
|
53 Returns an instance of Cheetah.Template, prepopulated with whatever variables it needs, ready to be rendered |
|
54 """ |
|
55 |
|
56 abstract |
|
57 |
|
58 |
|
59 |
|