2 Our URL action handlers |
2 Our URL action handlers |
3 """ |
3 """ |
4 |
4 |
5 from qmsk.web import http, template |
5 from qmsk.web import http, template |
6 |
6 |
7 import urls, channels |
7 import urls, channels, helpers |
8 |
8 |
9 # load templates from here |
9 # load templates from here |
10 templates = template.TemplateLoader("templates", |
10 templates = template.TemplateLoader("templates", |
|
11 h = helpers, |
11 urls = urls, |
12 urls = urls, |
12 channel_list = channels.channel_list, |
13 channel_list = channels.channel_list, |
13 ) |
14 ) |
14 |
15 |
15 def index (request) : |
16 def index (request) : |
26 Redirect to the appropriate channel_view |
27 Redirect to the appropriate channel_view |
27 """ |
28 """ |
28 |
29 |
29 return http.Redirect(urls.channel_view.build(request, channel=channel.id)) |
30 return http.Redirect(urls.channel_view.build(request, channel=channel.id)) |
30 |
31 |
31 def channel_view (request, channel, count) : |
32 def channel_view (request, channel, count, formatter) : |
32 """ |
33 """ |
33 The main channel view page, display the most important info, and all requisite links |
34 The main channel view page, display the most important info, and all requisite links |
34 """ |
35 """ |
|
36 |
|
37 # get latest events |
|
38 lines = channel.source.get_latest(count) |
35 |
39 |
36 if count == 'all' : |
40 # format |
37 xxx |
41 lines = formatter.format_html(lines) |
38 |
42 |
39 else : |
43 return templates.render_to_response("channel_view", |
40 count = int(count) |
|
41 |
|
42 return templates.render_to_response("channel", |
|
43 req = request, |
44 req = request, |
44 channel = channel, |
45 channel = channel, |
45 count = count, |
46 count = count, |
46 lines = channel.source.get_latest(count), |
47 formatter = formatter, |
|
48 lines = lines, |
47 ) |
49 ) |
48 |
|
49 pass |
|
50 |
50 |
51 def channel_last (request, channel, count, format) : |
51 def channel_last (request, channel, count, format) : |
52 """ |
52 """ |
53 Display the last x lines of channel messages in various formats |
53 Display the last x lines of channel messages in various formats |
54 """ |
54 """ |
55 |
55 |
56 if format == 'txt' : |
56 if format == 'txt' : |
57 return http.Response('\n'.join(channel.source.get_latest(count)), 'text/plain') |
57 # XXX: formatting |
58 |
58 # return http.Response('\n'.join(str(channel.source.get_latest(count))), 'text/plain') |
|
59 pass |
|
60 |
59 else : |
61 else : |
60 raise http.ResponseError("Unknown filetype %r" % format) |
62 raise http.ResponseError("Unknown filetype %r" % format) |
|
63 |
|
64 def channel_date (request, channel, date, formatter) : |
|
65 """ |
|
66 Display all log data for the given date |
|
67 """ |
|
68 |
|
69 # XXX: fix date timezone |
|
70 import pytz |
|
71 date = date.replace(tzinfo=pytz.utc) |
|
72 |
|
73 # get latest events |
|
74 lines = channel.source.get_date(date) |
|
75 |
|
76 # format |
|
77 lines = formatter.format_html(lines) |
|
78 |
|
79 return templates.render_to_response("channel_date", |
|
80 req = request, |
|
81 channel = channel, |
|
82 formatter = formatter, |
|
83 date = date, |
|
84 lines = lines, |
|
85 ) |
61 |
86 |
62 def channel_search (request, channel, q) : |
87 def channel_search (request, channel, q) : |
63 """ |
88 """ |
64 Display the search form for the channel for GET, or do the search for POST |
89 Display the search form for the channel for GET, or do the search for POST |
65 """ |
90 """ |