implement max_pages, and paginate channel_date by default now
authorTero Marttila <terom@fixme.fi>
Tue, 10 Feb 2009 01:05:35 +0200
changeset 77 4287fb77e312
parent 76 cc3ab2c39ded
child 78 85345abbd46a
implement max_pages, and paginate channel_date by default now
handlers.py
log_source.py
urls.py
--- a/handlers.py	Tue Feb 10 01:02:26 2009 +0200
+++ b/handlers.py	Tue Feb 10 01:05:35 2009 +0200
@@ -141,7 +141,7 @@
     )
 
 @preferences.handler(prefs.formatter, prefs.timezone, prefs.count)
-def channel_date (request, channel, date, formatter, timezone, count, page=None) :
+def channel_date (request, channel, date, formatter, timezone, count, page=1) :
     """
         Display all log data for the given date
     """
--- a/log_source.py	Tue Feb 10 01:02:26 2009 +0200
+++ b/log_source.py	Tue Feb 10 01:05:35 2009 +0200
@@ -2,7 +2,7 @@
     A source of IRC log files
 """
 
-import datetime, calendar, itertools, functools
+import datetime, calendar, itertools, functools, math
 import os, errno
 import pytz
 
@@ -42,24 +42,34 @@
         else :
             skip = None
 
+        # count the full number of lines
+        line_count = 0
+
         # collect lines
         lines = []
 
         # iterate using get_date
         for line in self.get_date(dt) :
+            # count them
+            line_count += 1
+
             # skip?
             if skip :
                 skip -= 1
                 continue
-            
+ 
+            # already full?
+            if len(lines) > count :
+                continue
+           
             # store line
             lines.append(line)
-
-            # count?
-            if len(lines) >= count :
-                break
-
-        return (page, 0, lines)
+        
+        # calculate max_pages
+        max_pages = math.ceil(float(line_count) / count)
+        
+        # return
+        return (page, max_pages, lines)
 
     def get_month_days (self, dt) :
         """
--- a/urls.py	Tue Feb 10 01:02:26 2009 +0200
+++ b/urls.py	Tue Feb 10 01:05:35 2009 +0200
@@ -38,7 +38,7 @@
 channel_last        = url('/channels/{channel:cid}/last/{count:int=100}',                   handlers.channel_last                       )
 channel_link        = url('/channels/{channel:cid}/link/{timestamp:ts}',                    handlers.channel_link                       )
 channel_calendar    = url('/channels/{channel:cid}/calendar/{year:int=0}/{month:int=0}',    handlers.channel_calendar                   )
-channel_date        = url('/channels/{channel:cid}/date/{date:date}/?page:int=',            handlers.channel_date                       )
+channel_date        = url('/channels/{channel:cid}/date/{date:date}/?page:int=1',           handlers.channel_date                       )
 channel_search      = url('/channels/{channel:cid}/search/?q=&page:int=1&max:int=1',        handlers.channel_search                     )
 
 # mapper