18 channel_list = config.LOG_CHANNELS, |
18 channel_list = config.LOG_CHANNELS, |
19 config = config, |
19 config = config, |
20 ) |
20 ) |
21 |
21 |
22 # return a http.Response for the given text in the given format |
22 # return a http.Response for the given text in the given format |
23 def _render_type (request, channel, lines, type) : |
23 def _render_type (request, channel, lines, type, full_timestamps=False) : |
24 """ |
24 """ |
25 Render the given LogLines as a http.Response in the given format, which is one of: |
25 Render the given LogLines as a http.Response in the given format, which is one of: |
26 html - XXX: not supported |
26 html - XXX: not supported |
27 txt - Plaintext |
27 txt - Plaintext |
28 png - PNG image |
28 png - PNG image |
36 if type in ('html', None) : |
36 if type in ('html', None) : |
37 xxx |
37 xxx |
38 |
38 |
39 elif type == 'txt' : |
39 elif type == 'txt' : |
40 # plaintext |
40 # plaintext |
41 lines = formatter.format_txt(lines) |
41 lines = formatter.format_txt(lines, full_timestamps) |
42 |
42 |
43 # build data |
43 # build data |
44 data = '\n'.join(data for line, data in lines) |
44 data = '\n'.join(data for line, data in lines) |
45 |
45 |
46 return http.Response(data, 'text/plain') |
46 return http.Response(data, 'text/plain') |
47 |
47 |
48 elif type == 'png' : |
48 elif type == 'png' : |
49 # PNG image |
49 # PNG image |
50 png_data = formatter.format_png(lines) |
50 png_data = formatter.format_png(lines, full_timestamps) |
51 |
51 |
52 return http.Response(png_data, 'image/png', charset=None) |
52 return http.Response(png_data, 'image/png', charset=None) |
53 |
53 |
54 elif type == 'rss' : |
54 elif type == 'rss' : |
55 # RSS feed |
55 # RSS feed |
56 rss_data = formatter.format_rss(lines) |
56 rss_data = formatter.format_rss(lines, full_timestamps) |
57 |
57 |
58 # XXX: fix to render as unicode? |
58 # XXX: fix to render as unicode? |
59 return http.Response(rss_data, 'application/rss+xml', charset=None) |
59 return http.Response(rss_data, 'application/rss+xml', charset=None) |
60 |
60 |
61 else : |
61 else : |
222 |
222 |
223 # render channel_date |
223 # render channel_date |
224 return _render_date (request, channel, date, lines, type, count, page, max) |
224 return _render_date (request, channel, date, lines, type, count, page, max) |
225 |
225 |
226 @preferences.handler(prefs.formatter, prefs.count) |
226 @preferences.handler(prefs.formatter, prefs.count) |
227 def channel_search (request, channel, formatter, count, q=None, page=1, max=1, type=None) : |
227 def channel_search (request, channel, formatter, count, q=None, page=1, max=1, type=None, t=None) : |
228 """ |
228 """ |
229 Display the search form for the channel for GET, or do the search for POST. |
229 Display the search form for the channel for GET, or do the search for POST. |
230 """ |
230 """ |
231 |
231 |
232 # calculate skip offset from page/count |
232 # calculate skip offset from page/count |
233 skip = (page - 1) * count |
233 skip = (page - 1) * count |
234 |
234 |
235 # got a search query? |
235 # got a search query? |
236 if q : |
236 if q : |
|
237 # attribute targets |
|
238 targets = dict(('search_%s' % target, True) for target in t if target in ('msg', 'nick')) if t else {} |
|
239 |
237 try : |
240 try : |
238 # do search |
241 # do search |
239 lines = log_search.get_index().search_simple(channel, q, count, skip) |
242 lines = log_search.get_index().search_simple(channel, q, count, skip, **targets) |
240 |
243 |
241 # update max? |
244 # update max? |
242 if max and page > max : |
245 if max and page > max : |
243 max = page |
246 max = page |
244 |
247 |