equal
deleted
inserted
replaced
5 |
5 |
6 # for filesystem ops |
6 # for filesystem ops |
7 import os, os.path |
7 import os, os.path |
8 import time |
8 import time |
9 |
9 |
10 from lib import http, template, config |
10 from lib import http, handler, template, config |
|
11 |
|
12 import menu |
11 |
13 |
12 class PageError (http.ResponseError) : |
14 class PageError (http.ResponseError) : |
13 """ |
15 """ |
14 Error looking up/handling a page |
16 Error looking up/handling a page |
15 """ |
17 """ |
16 |
18 |
17 pass |
19 pass |
18 |
20 |
19 # XXX: should inherit from PageInfo |
21 # XXX: should inherit from PageInfo |
20 class Page (object) : |
22 class Page (handler.RequestHandler) : |
21 """ |
23 """ |
22 This object represents the information about our attempt to render some specific page |
24 This object represents the information about our attempt to render some specific page |
23 """ |
25 """ |
24 |
26 |
25 def __init__ (self, fs, url, path, basename, url_tail, charset='utf8') : |
27 def __init__ (self, fs, url, path, basename, url_tail, charset='utf8') : |
40 self.path = path |
42 self.path = path |
41 self.basename = basename |
43 self.basename = basename |
42 self.url_tail = url_tail |
44 self.url_tail = url_tail |
43 self.charset = charset |
45 self.charset = charset |
44 |
46 |
45 # unbound |
|
46 self.request = None |
|
47 |
|
48 # sub-init |
47 # sub-init |
49 self._init() |
48 self._init() |
50 |
49 |
51 def _init (self) : |
50 def _init (self) : |
52 """ |
51 """ |
53 Do initial data loading, etc |
52 Do initial data loading, etc |
54 """ |
53 """ |
55 |
54 |
56 pass |
55 pass |
57 |
|
58 def bind_request (self, request) : |
|
59 """ |
|
60 Bind this page-render to the given request |
|
61 """ |
|
62 |
|
63 self.request = request |
|
64 |
56 |
65 @property |
57 @property |
66 def title (self) : |
58 def title (self) : |
67 """ |
59 """ |
68 Return the page's title |
60 Return the page's title |
98 |
90 |
99 # stat |
91 # stat |
100 timestamp = os.stat(self.path).st_mtime |
92 timestamp = os.stat(self.path).st_mtime |
101 |
93 |
102 return time.strftime(config.DATETIME_FMT, time.gmtime(timestamp)) |
94 return time.strftime(config.DATETIME_FMT, time.gmtime(timestamp)) |
|
95 |
|
96 def handle_request (self, request) : |
|
97 """ |
|
98 Renders the fs's layout template with this page + menu |
|
99 """ |
|
100 |
|
101 # render the template |
|
102 response_data = template.render(self.fs.template, |
|
103 request = request, |
|
104 site_root_url = request.get_script_dir(), |
|
105 site_page_url = request.get_page_prefix(), |
|
106 page = self, |
|
107 menu = menu.Menu(self.fs, self), |
|
108 ) |
|
109 |
|
110 # return the response |
|
111 return http.Response(response_data) |
103 |
112 |
104 class HTMLPage (Page) : |
113 class HTMLPage (Page) : |
105 """ |
114 """ |
106 A simple .html page that's just passed through directly |
115 A simple .html page that's just passed through directly |
107 """ |
116 """ |
124 """ |
133 """ |
125 Loads the .tmpl file, and renders it |
134 Loads the .tmpl file, and renders it |
126 """ |
135 """ |
127 |
136 |
128 return template.TemplateLoader.render_file(self.path, |
137 return template.TemplateLoader.render_file(self.path, |
129 request = self.request, |
138 page_tree = self.fs.tree, |
130 page_tree = self.fs.tree |
|
131 ) |
139 ) |
132 |
140 |