~ubuntu-branches/ubuntu/natty/moin/natty-updates

« back to all changes in this revision

Viewing changes to MoinMoin/macro/Hits.py

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard
  • Date: 2008-06-22 21:17:13 UTC
  • mfrom: (0.9.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080622211713-fpo2zrq3s5dfecxg
Tags: 1.7.0-3
Simplify /etc/moin/wikilist format: "USER URL" (drop unneeded middle
CONFIG_DIR that was wrongly advertised as DATA_DIR).  Make
moin-mass-migrate handle both formats and warn about deprecation of
the old one.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: iso-8859-1 -*-
 
2
"""
 
3
    MoinMoin - Hits Macro
 
4
 
 
5
    This macro is used to show the cumulative hits of the wikipage where the Macro is called from.
 
6
    Optionally you could count how much this page or all pages were changed or viewed.
 
7
 
 
8
    <<Hits([all=(0,1)],[event_type=(VIEWPAGE,SAVEPAGE)>>
 
9
 
 
10
        all: if set to 1/True/yes then cumulative hits over all wiki pages is returned.
 
11
             Default is 0/False/no.
 
12
        filter: if set to SAVEPAGE then the saved pages are counted. Default is VIEWPAGE.
 
13
 
 
14
   @copyright: 2004-2008 MoinMoin:ReimarBauer,
 
15
               2005 BenjaminVrolijk
 
16
   @license: GNU GPL, see COPYING for details.
 
17
"""
 
18
Dependencies = ['time'] # do not cache
 
19
 
 
20
from MoinMoin.stats import hitcounts
 
21
 
 
22
def macro_Hits(macro, all=False, event_type=(u'VIEWPAGE', u'SAVEPAGE')):
 
23
    request = macro.request
 
24
    pagename = macro.formatter.page.page_name
 
25
 
 
26
    if all:
 
27
        cache_days, cache_views, cache_edits = hitcounts.get_data(pagename, request, filterpage=None)
 
28
    else:
 
29
        cache_days, cache_views, cache_edits = hitcounts.get_data(pagename, request, filterpage=pagename)
 
30
 
 
31
    if event_type == u'VIEWPAGE':
 
32
        return u'%d' % sum(cache_views)
 
33
    else:
 
34
        return u'%d' % sum(cache_edits)
 
35