handlers.py
changeset 118 f530c158aa07
parent 117 f0b4097f5781
child 123 3297596ab606
equal deleted inserted replaced
117:f0b4097f5781 118:f530c158aa07
    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         
   251         lines = None
   254         lines = None
   252  
   255  
   253     # type?
   256     # type?
   254     if type and lines :
   257     if type and lines :
   255         # special type
   258         # special type
   256         return _render_type(request, channel, lines, type)
   259         return _render_type(request, channel, lines, type, full_timestamps=True)
   257     
   260     
   258     else :
   261     else :
   259         # format lines to HTML if any
   262         # format lines to HTML if any
   260         if lines :
   263         if lines :
   261             # format
   264             # format
   265         return templates.render_to_response("channel_search",
   268         return templates.render_to_response("channel_search",
   266             req             = request,
   269             req             = request,
   267             prefs           = request.prefs,
   270             prefs           = request.prefs,
   268             channel         = channel,
   271             channel         = channel,
   269             search_query    = q,
   272             search_query    = q,
       
   273             search_targets  = t,
   270             count           = count,
   274             count           = count,
   271             page            = page,
   275             page            = page,
   272             skip            = skip,
   276             skip            = skip,
   273             max             = max,
   277             max             = max,
   274             lines           = lines,
   278             lines           = lines,