diff -r aaa62c8e5bd5 -r f13cf27a360b handlers.py --- a/handlers.py Sun Feb 08 04:59:22 2009 +0200 +++ b/handlers.py Mon Feb 09 00:24:13 2009 +0200 @@ -4,10 +4,11 @@ from qmsk.web import http, template -import urls, channels +import urls, channels, helpers # load templates from here templates = template.TemplateLoader("templates", + h = helpers, urls = urls, channel_list = channels.channel_list, ) @@ -28,37 +29,61 @@ return http.Redirect(urls.channel_view.build(request, channel=channel.id)) -def channel_view (request, channel, count) : +def channel_view (request, channel, count, formatter) : """ The main channel view page, display the most important info, and all requisite links """ - - if count == 'all' : - xxx + + # get latest events + lines = channel.source.get_latest(count) - else : - count = int(count) + # format + lines = formatter.format_html(lines) - return templates.render_to_response("channel", + return templates.render_to_response("channel_view", req = request, channel = channel, count = count, - lines = channel.source.get_latest(count), + formatter = formatter, + lines = lines, ) - pass - def channel_last (request, channel, count, format) : """ Display the last x lines of channel messages in various formats """ if format == 'txt' : - return http.Response('\n'.join(channel.source.get_latest(count)), 'text/plain') - + # XXX: formatting +# return http.Response('\n'.join(str(channel.source.get_latest(count))), 'text/plain') + pass + else : raise http.ResponseError("Unknown filetype %r" % format) +def channel_date (request, channel, date, formatter) : + """ + Display all log data for the given date + """ + + # XXX: fix date timezone + import pytz + date = date.replace(tzinfo=pytz.utc) + + # get latest events + lines = channel.source.get_date(date) + + # format + lines = formatter.format_html(lines) + + return templates.render_to_response("channel_date", + req = request, + channel = channel, + formatter = formatter, + date = date, + lines = lines, + ) + def channel_search (request, channel, q) : """ Display the search form for the channel for GET, or do the search for POST