handlers.py
changeset 79 43ac75054d5c
parent 78 85345abbd46a
child 80 a0662cff1d9d
equal deleted inserted replaced
78:85345abbd46a 79:43ac75054d5c
    66     """
    66     """
    67    
    67    
    68     return http.Redirect(urls.channel.build(request, channel=channel))
    68     return http.Redirect(urls.channel.build(request, channel=channel))
    69 
    69 
    70 @preferences.handler(prefs.formatter)
    70 @preferences.handler(prefs.formatter)
    71 def channel_last (request, channel, count, formatter) :
    71 def channel_last (request, channel, count, formatter, type=None) :
    72     """
    72     """
    73         The main channel view page, displaying the most recent lines
    73         The main channel view page, displaying the most recent lines
    74     """
    74     """
    75     
    75  
    76     # get latest events
    76     # get latest events
    77     lines = channel.source.get_latest(count)
    77     lines = channel.source.get_latest(count)
    78 
    78    
    79     # lines
    79     # we can render in various modes...
    80     lines = formatter.format_html(lines)
    80     if not type :
    81 
    81         # normal HTML
    82     return templates.render_to_response("channel_last",
    82         lines = formatter.format_html(lines)
    83         req             = request,
    83 
    84         prefs           = request.prefs,
    84         return templates.render_to_response("channel_last",
    85         channel         = channel,
    85             req             = request,
    86         count           = count,
    86             prefs           = request.prefs,
    87         lines           = lines,
    87             channel         = channel,
    88     )
    88             count           = count,
       
    89             lines           = lines,
       
    90         )
       
    91     
       
    92     elif type == 'txt' :
       
    93         # plaintext
       
    94         lines = formatter.format_txt(lines)
       
    95 
       
    96         # build data
       
    97         data = '\n'.join(data for line, data in lines)
       
    98 
       
    99         return http.Response(data, 'text/plain')
       
   100 
       
   101     elif type == 'png' :
       
   102         # PNG image
       
   103         png_data = formatter.format_png(lines)
       
   104 
       
   105         return http.Response(png_data, 'image/png', charset=None)
       
   106 
       
   107     else :
       
   108         raise http.ResponseError("Unrecognized type: %r" % (type, ))
    89 
   109 
    90 @preferences.handler(prefs.formatter, prefs.timezone, prefs.count)
   110 @preferences.handler(prefs.formatter, prefs.timezone, prefs.count)
    91 def channel_link (request, channel, timestamp, formatter, timezone, count) :
   111 def channel_link (request, channel, timestamp, formatter, timezone, count) :
    92     """
   112     """
    93         Display channel_date for specific UTC timestamp
   113         Display channel_date for specific UTC timestamp