annotate MoinMoin/macro/Hits.py @ 3384:475f8094a65f

macro.Hits: removed order reverse
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Fri, 21 Mar 2008 00:39:19 +0100
parents 2a3a6cb34e45
children b9c90178b93a
rev   line source
2054
9bea36ddd065 macro/Hits: shows hits of a page (refactored version from MacroMarket)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
9bea36ddd065 macro/Hits: shows hits of a page (refactored version from MacroMarket)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
2 """
9bea36ddd065 macro/Hits: shows hits of a page (refactored version from MacroMarket)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
3 MoinMoin - Hits Macro
9bea36ddd065 macro/Hits: shows hits of a page (refactored version from MacroMarket)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
4
2514
9065adc695ca refactored Hits macro for new arg parser
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2455
diff changeset
5 This macro is used to show the cumulative hits of the wikipage where the Macro is called from.
9065adc695ca refactored Hits macro for new arg parser
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2455
diff changeset
6 Optionally you could count how much this page or all pages were changed or viewed.
2054
9bea36ddd065 macro/Hits: shows hits of a page (refactored version from MacroMarket)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
7
2725
388204baf00f change [[macro]] to <<macro>> in all built-in markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2539
diff changeset
8 <<Hits([all=(0,1)],[filter=(VIEWPAGE,SAVEPAGE)>>
2054
9bea36ddd065 macro/Hits: shows hits of a page (refactored version from MacroMarket)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
9
2514
9065adc695ca refactored Hits macro for new arg parser
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2455
diff changeset
10 all: if set to 1/True/yes then cumulative hits over all wiki pages is returned.
9065adc695ca refactored Hits macro for new arg parser
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2455
diff changeset
11 Default is 0/False/no.
2054
9bea36ddd065 macro/Hits: shows hits of a page (refactored version from MacroMarket)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
12 filter: if set to SAVEPAGE then the saved pages are counted. Default is VIEWPAGE.
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2054
diff changeset
13
2453
adf5ec4874ed fix ParameterParser, rewrite ParameterParser tests for py.test (and add more tests), refactor Hits macro
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2286
diff changeset
14 @copyright: 2004-2007 MoinMoin:ReimarBauer,
2054
9bea36ddd065 macro/Hits: shows hits of a page (refactored version from MacroMarket)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
15 2005 BenjaminVrolijk
9bea36ddd065 macro/Hits: shows hits of a page (refactored version from MacroMarket)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
16 @license: GNU GPL, see COPYING for details.
9bea36ddd065 macro/Hits: shows hits of a page (refactored version from MacroMarket)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
17 """
2453
adf5ec4874ed fix ParameterParser, rewrite ParameterParser tests for py.test (and add more tests), refactor Hits macro
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2286
diff changeset
18
2054
9bea36ddd065 macro/Hits: shows hits of a page (refactored version from MacroMarket)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
19 Dependencies = ['time'] # do not cache
9bea36ddd065 macro/Hits: shows hits of a page (refactored version from MacroMarket)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
20
9bea36ddd065 macro/Hits: shows hits of a page (refactored version from MacroMarket)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
21 from MoinMoin.logfile import eventlog
9bea36ddd065 macro/Hits: shows hits of a page (refactored version from MacroMarket)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
22
9bea36ddd065 macro/Hits: shows hits of a page (refactored version from MacroMarket)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
23
2539
9dd4a7a164e4 use new features in Hits macro
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2514
diff changeset
24 def macro_Hits(macro, all=False, filter=(u'VIEWPAGE', u'SAVEPAGE')):
2514
9065adc695ca refactored Hits macro for new arg parser
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2455
diff changeset
25 this_page = macro.formatter.page.page_name
2539
9dd4a7a164e4 use new features in Hits macro
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2514
diff changeset
26 event_log = eventlog.EventLog(macro.request)
9dd4a7a164e4 use new features in Hits macro
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2514
diff changeset
27 event_log.set_filter([str(filter)])
2514
9065adc695ca refactored Hits macro for new arg parser
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2455
diff changeset
28 count = 0
3384
475f8094a65f macro.Hits: removed order reverse
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3175
diff changeset
29 for event in event_log:
2514
9065adc695ca refactored Hits macro for new arg parser
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2455
diff changeset
30 pagename = event[2].get('pagename')
2539
9dd4a7a164e4 use new features in Hits macro
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2514
diff changeset
31 if all or pagename == this_page:
2514
9065adc695ca refactored Hits macro for new arg parser
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2455
diff changeset
32 count += 1
2054
9bea36ddd065 macro/Hits: shows hits of a page (refactored version from MacroMarket)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
33
2514
9065adc695ca refactored Hits macro for new arg parser
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2455
diff changeset
34 return u'%d' % count