handle the 'no search results' case
authorTero Marttila <terom@fixme.fi>
Tue, 10 Feb 2009 00:04:15 +0200
changeset 74 1ab95857d584
parent 73 5a7188bf2894
child 75 c5ce145fdd70
handle the 'no search results' case
handlers.py
log_search.py
static/irclogs.css
templates/channel_search.tmpl
--- 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,
     )
 
-
-
--- 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...
--- 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;
--- 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 %>
     <div class="paginate">
@@ -24,7 +28,13 @@
             </li>
         % endfor
             <li>
+            % if _more :
                 <a href="${h.build_url(url, count=count, skip=h.skip_next(count, max), **args)}">More &raquo;</a>
+            % elif False : 
+                <a href="${h.build_url(url, count=count, skip=h.skip_next(count, max), **args)}">Next &raquo;</a>
+            % else : ## last page
+                <span>Next &raquo;</span>
+            % endif
             </li>
         </ul>
     </div>
@@ -61,7 +71,11 @@
 % else :
 <div id="title">${channel.title} :: Search '${search_query}'</div>
 
-${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 :
+<div id="search-error">No results found</div>
 % endif
+${paginate(urls.channel_search, count, skip, max, channel=channel, q=search_query, _more=bool(lines))}
+% endif