annotate MoinMoin/macro/Hits.py @ 2054:9bea36ddd065

macro/Hits: shows hits of a page (refactored version from MacroMarket)
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Sun, 10 Jun 2007 17:12:16 +0200
parents
children 01f05e74aa9c
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
9bea36ddd065 macro/Hits: shows hits of a page (refactored version from MacroMarket)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
5 This macro is used to show the cummulative hits of the wikipage where the Macro is called from.
9bea36ddd065 macro/Hits: shows hits of a page (refactored version from MacroMarket)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
6 Optional you could count how much this or all pages was changed or viewed.
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
9bea36ddd065 macro/Hits: shows hits of a page (refactored version from MacroMarket)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
10 all: if set to 1 then cummulative hits over all wiki pages is returned. Default is 0
9bea36ddd065 macro/Hits: shows hits of a page (refactored version from MacroMarket)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
11 filter: if set to SAVEPAGE then the saved pages are counted. Default is VIEWPAGE.
9bea36ddd065 macro/Hits: shows hits of a page (refactored version from MacroMarket)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
12
9bea36ddd065 macro/Hits: shows hits of a page (refactored version from MacroMarket)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
13 @copyright: 2004-2007 MoinMoin:ReimarBauer
9bea36ddd065 macro/Hits: shows hits of a page (refactored version from MacroMarket)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
14 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
15 @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
16 """
9bea36ddd065 macro/Hits: shows hits of a page (refactored version from MacroMarket)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
17 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
18
9bea36ddd065 macro/Hits: shows hits of a page (refactored version from MacroMarket)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
19 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
20 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
21
9bea36ddd065 macro/Hits: shows hits of a page (refactored version from MacroMarket)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
22 class Hits:
9bea36ddd065 macro/Hits: shows hits of a page (refactored version from MacroMarket)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
23 def __init__(self, macro, args):
9bea36ddd065 macro/Hits: shows hits of a page (refactored version from MacroMarket)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
24 self.macro = macro
9bea36ddd065 macro/Hits: shows hits of a page (refactored version from MacroMarket)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
25 self.request = macro.request
9bea36ddd065 macro/Hits: shows hits of a page (refactored version from MacroMarket)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
26 self.formatter = macro.formatter
9bea36ddd065 macro/Hits: shows hits of a page (refactored version from MacroMarket)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
27 argParser = wikiutil.ParameterParser("%(all)s%(filter)s")
9bea36ddd065 macro/Hits: shows hits of a page (refactored version from MacroMarket)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
28 try:
9bea36ddd065 macro/Hits: shows hits of a page (refactored version from MacroMarket)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
29 self.arg_list, self.arg_dict = argParser.parse_parameters(args)
9bea36ddd065 macro/Hits: shows hits of a page (refactored version from MacroMarket)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
30 except ValueError:
9bea36ddd065 macro/Hits: shows hits of a page (refactored version from MacroMarket)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
31 # TODO Set defaults until raise in ParameterParser.parse_parameters is changed
9bea36ddd065 macro/Hits: shows hits of a page (refactored version from MacroMarket)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
32 self.arg_dict = {}
9bea36ddd065 macro/Hits: shows hits of a page (refactored version from MacroMarket)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
33 self.arg_dict["filter"] = None
9bea36ddd065 macro/Hits: shows hits of a page (refactored version from MacroMarket)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
34 self.arg_dict["all"] = 0
9bea36ddd065 macro/Hits: shows hits of a page (refactored version from MacroMarket)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
35
9bea36ddd065 macro/Hits: shows hits of a page (refactored version from MacroMarket)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
36 self.count = 0
9bea36ddd065 macro/Hits: shows hits of a page (refactored version from MacroMarket)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
37
9bea36ddd065 macro/Hits: shows hits of a page (refactored version from MacroMarket)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
38 def renderInText(self):
9bea36ddd065 macro/Hits: shows hits of a page (refactored version from MacroMarket)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
39 return self.formatter.text("%s" % (self.getHits()))
9bea36ddd065 macro/Hits: shows hits of a page (refactored version from MacroMarket)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
40
9bea36ddd065 macro/Hits: shows hits of a page (refactored version from MacroMarket)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
41 def getHits(self):
9bea36ddd065 macro/Hits: shows hits of a page (refactored version from MacroMarket)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
42 formatter = self.macro.formatter
9bea36ddd065 macro/Hits: shows hits of a page (refactored version from MacroMarket)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
43 kw = self.arg_dict
9bea36ddd065 macro/Hits: shows hits of a page (refactored version from MacroMarket)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
44 if not kw["filter"]: kw["filter"] = "VIEWPAGE"
9bea36ddd065 macro/Hits: shows hits of a page (refactored version from MacroMarket)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
45
9bea36ddd065 macro/Hits: shows hits of a page (refactored version from MacroMarket)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
46 event_log = eventlog.EventLog(self.request)
9bea36ddd065 macro/Hits: shows hits of a page (refactored version from MacroMarket)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
47 event_log.set_filter([kw["filter"]])
9bea36ddd065 macro/Hits: shows hits of a page (refactored version from MacroMarket)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
48 for event in event_log.reverse():
9bea36ddd065 macro/Hits: shows hits of a page (refactored version from MacroMarket)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
49 pagename = event[2].get('pagename', None)
9bea36ddd065 macro/Hits: shows hits of a page (refactored version from MacroMarket)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
50 if not kw["all"]:
9bea36ddd065 macro/Hits: shows hits of a page (refactored version from MacroMarket)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
51 if pagename == formatter.page.page_name:
9bea36ddd065 macro/Hits: shows hits of a page (refactored version from MacroMarket)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
52 self.count += 1
9bea36ddd065 macro/Hits: shows hits of a page (refactored version from MacroMarket)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
53 else:
9bea36ddd065 macro/Hits: shows hits of a page (refactored version from MacroMarket)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
54 self.count += 1
9bea36ddd065 macro/Hits: shows hits of a page (refactored version from MacroMarket)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
55
9bea36ddd065 macro/Hits: shows hits of a page (refactored version from MacroMarket)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
56 return self.count
9bea36ddd065 macro/Hits: shows hits of a page (refactored version from MacroMarket)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
57
9bea36ddd065 macro/Hits: shows hits of a page (refactored version from MacroMarket)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
58 def execute(macro, args):
9bea36ddd065 macro/Hits: shows hits of a page (refactored version from MacroMarket)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
59 """ Temporary glue code to use with moin current macro system """
9bea36ddd065 macro/Hits: shows hits of a page (refactored version from MacroMarket)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
60 return Hits(macro, args).renderInText()
9bea36ddd065 macro/Hits: shows hits of a page (refactored version from MacroMarket)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents:
diff changeset
61