annotate MoinMoin/macro/Hits.py @ 2514:9065adc695ca

refactored Hits macro for new arg parser
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 22 Jul 2007 21:57:08 +0200
parents fe71235f1f7c
children 9dd4a7a164e4
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
9bea36ddd065 macro/Hits: shows hits of a page (refactored version from MacroMarket)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
8 [[Hits([all=(0,1)],[filter=(VIEWPAGE,SAVEPAGE)]]
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 import wikiutil
9bea36ddd065 macro/Hits: shows hits of a page (refactored version from MacroMarket)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
22 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
23
9bea36ddd065 macro/Hits: shows hits of a page (refactored version from MacroMarket)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
24
2514
9065adc695ca refactored Hits macro for new arg parser
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2455
diff changeset
25 def macro_Hits(macro, all=None, filter=None):
9065adc695ca refactored Hits macro for new arg parser
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2455
diff changeset
26 request = macro.request
9065adc695ca refactored Hits macro for new arg parser
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2455
diff changeset
27 _ = request.getText
9065adc695ca refactored Hits macro for new arg parser
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2455
diff changeset
28 this_page = macro.formatter.page.page_name
9065adc695ca refactored Hits macro for new arg parser
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2455
diff changeset
29 event_filter = str(wikiutil.get_unicode(request, filter, 'filter', u'VIEWPAGE'))
9065adc695ca refactored Hits macro for new arg parser
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2455
diff changeset
30 filters_possible = ('VIEWPAGE', 'SAVEPAGE')
9065adc695ca refactored Hits macro for new arg parser
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2455
diff changeset
31 if not event_filter in filters_possible:
9065adc695ca refactored Hits macro for new arg parser
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2455
diff changeset
32 raise ValueError(_("filter argument must be one of %s") % (', '.join(filters_possible)))
9065adc695ca refactored Hits macro for new arg parser
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2455
diff changeset
33 count_all_pages = wikiutil.get_bool(request, all, 'all', False)
2054
9bea36ddd065 macro/Hits: shows hits of a page (refactored version from MacroMarket)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
34
2514
9065adc695ca refactored Hits macro for new arg parser
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2455
diff changeset
35 event_log = eventlog.EventLog(request)
9065adc695ca refactored Hits macro for new arg parser
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2455
diff changeset
36 event_log.set_filter([event_filter])
9065adc695ca refactored Hits macro for new arg parser
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2455
diff changeset
37 count = 0
9065adc695ca refactored Hits macro for new arg parser
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2455
diff changeset
38 for event in event_log.reverse():
9065adc695ca refactored Hits macro for new arg parser
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2455
diff changeset
39 pagename = event[2].get('pagename')
9065adc695ca refactored Hits macro for new arg parser
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2455
diff changeset
40 if count_all_pages or pagename == this_page:
9065adc695ca refactored Hits macro for new arg parser
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2455
diff changeset
41 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
42
2514
9065adc695ca refactored Hits macro for new arg parser
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2455
diff changeset
43 return u'%d' % count
2054
9bea36ddd065 macro/Hits: shows hits of a page (refactored version from MacroMarket)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
44