diff MoinMoin/macro/Hits.py @ 3422:b9c90178b93a

macro.Hits: refactored
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Sun, 23 Mar 2008 13:18:03 +0100
parents 475f8094a65f
children aa3890b17212
line wrap: on
line diff
--- a/MoinMoin/macro/Hits.py	Sun Mar 23 00:54:09 2008 +0100
+++ b/MoinMoin/macro/Hits.py	Sun Mar 23 13:18:03 2008 +0100
@@ -11,7 +11,7 @@
              Default is 0/False/no.
         filter: if set to SAVEPAGE then the saved pages are counted. Default is VIEWPAGE.
 
-   @copyright: 2004-2007 MoinMoin:ReimarBauer,
+   @copyright: 2004-2008 MoinMoin:ReimarBauer,
                2005 BenjaminVrolijk
    @license: GNU GPL, see COPYING for details.
 """
@@ -20,15 +20,12 @@
 
 from MoinMoin.logfile import eventlog
 
-
-def macro_Hits(macro, all=False, filter=(u'VIEWPAGE', u'SAVEPAGE')):
-    this_page = macro.formatter.page.page_name
+def macro_Hits(macro, all=False, event_type=(u'VIEWPAGE', u'SAVEPAGE')):
+    pagename = macro.formatter.page.page_name
     event_log = eventlog.EventLog(macro.request)
-    event_log.set_filter([str(filter)])
-    count = 0
-    for event in event_log:
-        pagename = event[2].get('pagename')
-        if all or pagename == this_page:
-            count += 1
+    if not all:
+        test = filter(lambda line: line[1] in event_type and line[2]['pagename'] == pagename, event_log)
+    else:
+        test = filter(lambda line: line[1] in event_type, event_log)
 
-    return u'%d' % count
+    return u'%d' % len(test)