# HG changeset patch # User Tero Marttila # Date 1234217055 -7200 # Node ID 1ab95857d584c71464e289e9502223499a39ca24 # Parent 5a7188bf289438994f7efa828cefb816422d0a06 handle the 'no search results' case diff -r 5a7188bf2894 -r 1ab95857d584 handlers.py --- a/handlers.py Mon Feb 09 23:49:57 2009 +0200 +++ b/handlers.py Tue Feb 10 00:04:15 2009 +0200 @@ -172,11 +172,17 @@ # got a search query? if q : - # do search - lines = search_index.search_simple(channel, q, count, skip) + try : + # do search + lines = search_index.search_simple(channel, q, count, skip) + + except log_search.NoResultsFound : + # no lines + lines = None - # format - lines = formatter.format_html(lines, full_timestamps=True) + else : + # format + lines = formatter.format_html(lines, full_timestamps=True) else : lines = None @@ -193,5 +199,3 @@ lines = lines, ) - - diff -r 5a7188bf2894 -r 1ab95857d584 log_search.py --- a/log_search.py Mon Feb 09 23:49:57 2009 +0200 +++ b/log_search.py Tue Feb 10 00:04:15 2009 +0200 @@ -8,6 +8,20 @@ import log_line +class LogSearchError (Exception) : + """ + General search error + """ + + pass + +class NoResultsFound (LogSearchError) : + """ + No results found + """ + + pass + class LogSearchIndex (object) : """ An index on the logs for a group of channels. @@ -111,12 +125,16 @@ def search_cond (self, cond) : """ - Search using a raw hype.Condition + Search using a raw hype.Condition. Raises NoResultsFound if there aren't any results """ # execute search, unused 'flags' arg stays zero results = self.db.search(cond, 0) + # no results? + if not results : + raise NoResultsFound() + # iterate over the document IDs for doc_id in results : # load document, this throws an exception... diff -r 5a7188bf2894 -r 1ab95857d584 static/irclogs.css --- a/static/irclogs.css Mon Feb 09 23:49:57 2009 +0200 +++ b/static/irclogs.css Tue Feb 10 00:04:15 2009 +0200 @@ -283,6 +283,14 @@ text-align: left; } +div#search-error { + margin: 50px; + + text-align: center; + font-size: x-large; + font-style: italic; +} + /* Log lines */ a.more-link { color: black; diff -r 5a7188bf2894 -r 1ab95857d584 templates/channel_search.tmpl --- a/templates/channel_search.tmpl Mon Feb 09 23:49:57 2009 +0200 +++ b/templates/channel_search.tmpl Tue Feb 10 00:04:15 2009 +0200 @@ -1,8 +1,12 @@ <%inherit file="channel.tmpl" /> -<%def name="paginate(url, count, skip, max, **args)"> +<%def name="paginate(url, count, skip, max, _more=None, **args)"> ## update max? - <% max = h.max(max, skip) %> + % if more : + <% max = h.max(max, skip) %> + % else : + <% max = skip %> + % endif ## number of pages <% page_count = max / count + 1 %>
@@ -24,7 +28,13 @@ % endfor
  • + % if _more : More » + % elif False : + Next » + % else : ## last page + Next » + % endif
  • @@ -61,7 +71,11 @@ % else :
    ${channel.title} :: Search '${search_query}'
    -${paginate(urls.channel_search, count, skip, max, channel=channel, q=search_query)} +${paginate(urls.channel_search, count, skip, max, channel=channel, q=search_query, _more=bool(lines))} +% if lines : <%include file="lines.tmpl" /> -${paginate(urls.channel_search, count, skip, max, channel=channel, q=search_query)} +% else : +
    No results found
    % endif +${paginate(urls.channel_search, count, skip, max, channel=channel, q=search_query, _more=bool(lines))} +% endif