qmsk/irclogs/handlers.py
changeset 141 65c98c9e1716
parent 140 6db2527b67cf
equal deleted inserted replaced
140:6db2527b67cf 141:65c98c9e1716
   149 @preferences.handler(prefs.formatter)
   149 @preferences.handler(prefs.formatter)
   150 def channel_last (request, channel, count, formatter, type=None) :
   150 def channel_last (request, channel, count, formatter, type=None) :
   151     """
   151     """
   152         The main channel view page, displaying the most recent lines
   152         The main channel view page, displaying the most recent lines
   153     """
   153     """
   154  
   154 
   155     # get latest events
   155     # get latest events
   156     lines = channel.source.get_latest(count)
   156     lines = channel.source.get_latest(count)
   157    
   157    
   158     # type?
   158     # type?
   159     if type :
   159     if type :
   229         page, max, lines = channel.source.get_date_paged(date, count, page)
   229         page, max, lines = channel.source.get_date_paged(date, count, page)
   230         
   230         
   231     else :
   231     else :
   232         lines = channel.source.get_date(date)
   232         lines = channel.source.get_date(date)
   233         max = None
   233         max = None
   234 
   234    
   235     # render channel_date
   235     # render channel_date
   236     return _render_date (request, channel, date, lines, type, count, page, max)
   236     return _render_date (request, channel, date, lines, type, count, page, max)
   237 
   237 
   238 @preferences.handler(prefs.formatter, prefs.count)
   238 @preferences.handler(prefs.formatter, prefs.count)
   239 def channel_search (request, channel, formatter, count, q=None, page=1, max=1, type=None, t=None) :
   239 def channel_search (request, channel, formatter, count, q=None, nick=None, page=1, max=1, type=None) :
   240     """
   240     """
   241         Display the search form for the channel for GET, or do the search for POST.
   241         Display the search form for the channel for GET, or do the search for POST.
   242     """
   242     """
   243 
   243 
   244     # calculate skip offset from page/count
   244     # calculate skip offset from page/count
   245     skip = (page - 1) * count
   245     skip = (page - 1) * count
   246 
   246 
   247     # got a search query?
   247 
   248     if q :
   248     if q or nick :
   249         # attribute targets
   249         # search
   250         targets = dict(('search_%s' % target, True) for target in t if target in ('msg', 'nick')) if t else {}
       
   251 
       
   252         try :
   250         try :
   253             # do search
   251             lines = log_search.get_index().search_advanced(channel, q, nick, count, skip)
   254             lines = log_search.get_index().search_simple(channel, q, count, skip, **targets)
   252 
   255 
       
   256             # update max?
       
   257             if max and page > max :
       
   258                 max = page
       
   259         
       
   260         except log_search.NoResultsFound :
   253         except log_search.NoResultsFound :
   261             # no results
   254             # no results
   262             lines = None
   255             lines = None
   263 
   256 
   264     else :
   257     else :
   265         # just display the search form
   258         # just display the search form
   266         lines = None
   259         lines = None
   267  
   260        
       
   261 
       
   262     # max?
       
   263     if max and page > max :
       
   264         max = page
       
   265 
       
   266 
   268     # type?
   267     # type?
   269     if type and lines :
   268     if type and lines :
   270         # special type
   269         # special type
   271         return _render_type(request, channel, lines, type, full_timestamps=True)
   270         return _render_type(request, channel, lines, type, full_timestamps=True)
   272     
   271     
   280         return templates.render_to_response("channel_search",
   279         return templates.render_to_response("channel_search",
   281             req             = request,
   280             req             = request,
   282             prefs           = request.prefs,
   281             prefs           = request.prefs,
   283             channel         = channel,
   282             channel         = channel,
   284             search_query    = q,
   283             search_query    = q,
   285             search_targets  = t,
   284             search_nick     = nick,
       
   285             show_results    = (q or nick),
   286             count           = count,
   286             count           = count,
   287             page            = page,
   287             page            = page,
   288             skip            = skip,
   288             skip            = skip,
   289             max             = max,
   289             max             = max,
   290             lines           = lines,
   290             lines           = lines,