annotate 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
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
3422
b9c90178b93a macro.Hits: refactored
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3384
diff changeset
14 @copyright: 2004-2008 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
3422
b9c90178b93a macro.Hits: refactored
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3384
diff changeset
23 def macro_Hits(macro, all=False, event_type=(u'VIEWPAGE', u'SAVEPAGE')):
b9c90178b93a macro.Hits: refactored
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3384
diff changeset
24 pagename = macro.formatter.page.page_name
2539
9dd4a7a164e4 use new features in Hits macro
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2514
diff changeset
25 event_log = eventlog.EventLog(macro.request)
3422
b9c90178b93a macro.Hits: refactored
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3384
diff changeset
26 if not all:
b9c90178b93a macro.Hits: refactored
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3384
diff changeset
27 test = filter(lambda line: line[1] in event_type and line[2]['pagename'] == pagename, event_log)
b9c90178b93a macro.Hits: refactored
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3384
diff changeset
28 else:
b9c90178b93a macro.Hits: refactored
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3384
diff changeset
29 test = filter(lambda line: line[1] in event_type, event_log)
2054
9bea36ddd065 macro/Hits: shows hits of a page (refactored version from MacroMarket)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
30
3422
b9c90178b93a macro.Hits: refactored
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 3384
diff changeset
31 return u'%d' % len(test)