Back to index

moin  1.9.0~rc2
Hits.py
Go to the documentation of this file.
00001 # -*- coding: iso-8859-1 -*-
00002 """
00003     MoinMoin - Hits Macro
00004 
00005     This macro is used to show the cumulative hits of the wikipage where the Macro is called from.
00006     Optionally you could count how much this page or all pages were changed or viewed.
00007 
00008     <<Hits([all=(0,1)],[event_type=(VIEWPAGE,SAVEPAGE)>>
00009 
00010         all: if set to 1/True/yes then cumulative hits over all wiki pages is returned.
00011              Default is 0/False/no.
00012         filter: if set to SAVEPAGE then the saved pages are counted. Default is VIEWPAGE.
00013 
00014    @copyright: 2004-2008 MoinMoin:ReimarBauer,
00015                2005 BenjaminVrolijk
00016    @license: GNU GPL, see COPYING for details.
00017 """
00018 Dependencies = ['time'] # do not cache
00019 
00020 from MoinMoin.stats import hitcounts
00021 
00022 def macro_Hits(macro, all=False, event_type=(u'VIEWPAGE', u'SAVEPAGE')):
00023     request = macro.request
00024     pagename = macro.formatter.page.page_name
00025 
00026     if all:
00027         cache_days, cache_views, cache_edits = hitcounts.get_data(pagename, request, filterpage=None)
00028     else:
00029         cache_days, cache_views, cache_edits = hitcounts.get_data(pagename, request, filterpage=pagename)
00030 
00031     if event_type == u'VIEWPAGE':
00032         return u'%d' % sum(cache_views)
00033     else:
00034         return u'%d' % sum(cache_edits)
00035