handlers.py
changeset 79 43ac75054d5c
parent 78 85345abbd46a
child 80 a0662cff1d9d
--- a/handlers.py	Tue Feb 10 01:24:59 2009 +0200
+++ b/handlers.py	Tue Feb 10 02:57:16 2009 +0200
@@ -68,24 +68,44 @@
     return http.Redirect(urls.channel.build(request, channel=channel))
 
 @preferences.handler(prefs.formatter)
-def channel_last (request, channel, count, formatter) :
+def channel_last (request, channel, count, formatter, type=None) :
     """
         The main channel view page, displaying the most recent lines
     """
-    
+ 
     # get latest events
     lines = channel.source.get_latest(count)
-
-    # lines
-    lines = formatter.format_html(lines)
+   
+    # we can render in various modes...
+    if not type :
+        # normal HTML
+        lines = formatter.format_html(lines)
 
-    return templates.render_to_response("channel_last",
-        req             = request,
-        prefs           = request.prefs,
-        channel         = channel,
-        count           = count,
-        lines           = lines,
-    )
+        return templates.render_to_response("channel_last",
+            req             = request,
+            prefs           = request.prefs,
+            channel         = channel,
+            count           = count,
+            lines           = lines,
+        )
+    
+    elif type == 'txt' :
+        # plaintext
+        lines = formatter.format_txt(lines)
+
+        # build data
+        data = '\n'.join(data for line, data in lines)
+
+        return http.Response(data, 'text/plain')
+
+    elif type == 'png' :
+        # PNG image
+        png_data = formatter.format_png(lines)
+
+        return http.Response(png_data, 'image/png', charset=None)
+
+    else :
+        raise http.ResponseError("Unrecognized type: %r" % (type, ))
 
 @preferences.handler(prefs.formatter, prefs.timezone, prefs.count)
 def channel_link (request, channel, timestamp, formatter, timezone, count) :