Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes
MoinMoin.macro.PageHits.PageHits Class Reference

List of all members.

Public Member Functions

def __init__
def execute
def cachedHits
def addHitsFromLog
def updateCache
def filterReadableHits
def format

Public Attributes

 macro
 request
 cache

Detailed Description

Definition at line 15 of file PageHits.py.


Constructor & Destructor Documentation

def MoinMoin.macro.PageHits.PageHits.__init__ (   self,
  macro 
)

Definition at line 17 of file PageHits.py.

00017 
00018     def __init__(self, macro):
00019         self.macro = macro
00020         self.request = macro.request
00021         self.cache = caching.CacheEntry(self.request, 'charts', 'pagehits', scope='wiki', use_pickle=True)


Member Function Documentation

def MoinMoin.macro.PageHits.PageHits.addHitsFromLog (   self,
  hits,
  cacheDate 
)
Parse the log, add hits after cacheDate and update the cache 

Definition at line 44 of file PageHits.py.

00044 
00045     def addHitsFromLog(self, hits, cacheDate):
00046         """ Parse the log, add hits after cacheDate and update the cache """
00047         event_log = eventlog.EventLog(self.request)
00048         event_log.set_filter(['VIEWPAGE'])
00049 
00050         changed = False
00051         # don't use event_log.date()
00052         latest = None
00053         for event in event_log.reverse():
00054             if latest is None:
00055                 latest = event[0]
00056             if event[0] <= cacheDate:
00057                 break
00058             page = event[2].get('pagename', None)
00059             if page:
00060                 hits[page] = hits.get(page, 0) + 1
00061                 changed = True
00062 
00063         if changed:
00064             self.updateCache(latest, hits)

Here is the call graph for this function:

Here is the caller graph for this function:

Return tuple (cache date, cached hits) for all pages 

Definition at line 34 of file PageHits.py.

00034 
00035     def cachedHits(self):
00036         """ Return tuple (cache date, cached hits) for all pages """
00037         date, hits = 0, {}
00038         if self.cache.exists():
00039             try:
00040                 date, hits = self.cache.content()
00041             except caching.CacheError:
00042                 self.cache.remove()
00043         return date, hits

Here is the caller graph for this function:

Execute the macro and return output 

Definition at line 22 of file PageHits.py.

00022 
00023     def execute(self):
00024         """ Execute the macro and return output """
00025         if self.request.isSpiderAgent: # reduce bot cpu usage
00026             return ''
00027         cacheDate, hits = self.cachedHits()
00028         self.addHitsFromLog(hits, cacheDate)
00029         self.filterReadableHits(hits)
00030         hits = [(hits[pagename], pagename) for pagename in hits]
00031         hits.sort()
00032         hits.reverse()
00033         return self.format(hits)

Here is the call graph for this function:

Here is the caller graph for this function:

Filter out hits the user many not see 

Definition at line 71 of file PageHits.py.

00071 
00072     def filterReadableHits(self, hits):
00073         """ Filter out hits the user many not see """
00074         userMayRead = self.request.user.may.read
00075         for pagename in hits.keys(): # we need .keys() because we modify the dict
00076             page = Page(self.request, pagename)
00077             if page.exists() and userMayRead(pagename):
00078                 continue
00079             del hits[pagename]

Here is the caller graph for this function:

def MoinMoin.macro.PageHits.PageHits.format (   self,
  hits 
)
Return formated output 

Definition at line 80 of file PageHits.py.

00080 
00081     def format(self, hits):
00082         """ Return formated output """
00083         result = []
00084         formatter = self.macro.formatter
00085         result.append(formatter.number_list(1))
00086         for hit, pagename in hits:
00087             result.extend([
00088                 formatter.listitem(1),
00089                 formatter.code(1),
00090                 ("%6d" % hit).replace(" ", "&nbsp;"), " ",
00091                 formatter.code(0),
00092                 formatter.pagelink(1, pagename, generated=1),
00093                 formatter.text(pagename),
00094                 formatter.pagelink(0, pagename),
00095                 formatter.listitem(0),
00096             ])
00097         result.append(formatter.number_list(0))
00098         return ''.join(result)
00099 

Here is the caller graph for this function:

def MoinMoin.macro.PageHits.PageHits.updateCache (   self,
  date,
  hits 
)

Definition at line 65 of file PageHits.py.

00065 
00066     def updateCache(self, date, hits):
00067         try:
00068             self.cache.update((date, hits))
00069         except caching.CacheError:
00070             pass

Here is the caller graph for this function:


Member Data Documentation

Definition at line 20 of file PageHits.py.

Definition at line 18 of file PageHits.py.

Definition at line 19 of file PageHits.py.


The documentation for this class was generated from the following file: