iwla

iwla Git Source Tree

Root/plugins/display/top_pages.py

1import time
2
3from iwla import IWLA
4from iplugin import IPlugin
5from display import *
6
7#
8# Display hook
9#
10# Create TOP pages page
11#
12# Plugin requirements :
13# post_analysis/top_pages
14#
15# Conf values needed :
16# max_pages_displayed*
17# create_all_pages_page*
18#
19# Output files :
20# OUTPUT_ROOT/year/month/top_pages.html
21# OUTPUT_ROOT/year/month/index.html
22#
23# Statistics creation :
24# None
25#
26# Statistics update :
27# None
28#
29# Statistics deletion :
30# None
31#
32
33class IWLADisplayTopPages(IPlugin):
34 def __init__(self, iwla):
35 super(IWLADisplayTopPages, self).__init__(iwla)
36 self.API_VERSION = 1
37 self.requires = ['IWLAPostAnalysisTopPages']
38 self.max_pages = self.iwla.getConfValue('max_pages_displayed', 0)
39 self.create_all_pages = self.iwla.getConfValue('create_all_pages_page', True)
40
41 def hook(self):
42 display = self.iwla.getDisplay()
43 top_pages = self.iwla.getMonthStats()['top_pages']
44 top_pages = sorted(top_pages.items(), key=lambda t: t[1], reverse=True)
45
46 # All in a page
47 if self.create_all_pages:
48 title = time.strftime('All Pages - %B %Y', self.iwla.getCurTime())
49 filename = 'top_pages.html'
50 path = self.iwla.getCurDisplayPath(filename)
51
52 page = display.createPage(title, path, self.iwla.getConfValue('css_path', []))
53 table = display.createBlock(DisplayHTMLBlockTable, 'All Pages', ['URI', 'Entrance'])
54 table.setColsCSSClass(['', 'iwla_hit'])
55 total_hits = [0]*2
56 new_list = self.max_pages and top_pages[:self.max_pages] or top_pages
57 for (uri, entrance) in new_list:
58 table.appendRow([generateHTMLLink(uri), entrance])
59 total_hits[1] += entrance
60 page.appendBlock(table)
61
62 display.addPage(page)
63
64 title = 'Top Pages'
65 if self.create_all_pages:
66 link = '<a href=\'%s\'>All Pages</a>' % (filename)
67 title = '%s - %s' % (title, link)
68
69 # Top in index
70 index = self.iwla.getDisplayIndex()
71
72 table = display.createBlock(DisplayHTMLBlockTable, title, ['URI', 'Entrance'])
73 table.setColsCSSClass(['', 'iwla_hit'])
74 for (uri, entrance) in top_pages[:10]:
75 table.appendRow([generateHTMLLink(uri), entrance])
76 total_hits[1] -= entrance
77 if total_hits[1]:
78 total_hits[0] = 'Others'
79 table.appendRow(total_hits)
80 table.setCellCSSClass(table.getNbRows()-1, 0, 'iwla_others')
81 index.appendBlock(table)

Archive Download this file

Branches

Tags