Add max_x_displayed and create_x_page parameters for most display plugins

This commit is contained in:
2014-12-11 21:13:24 +01:00
parent 2df258676c
commit e012dc1b24
6 changed files with 140 additions and 93 deletions

View File

@@ -13,7 +13,8 @@ from display import *
# post_analysis/top_hits
#
# Conf values needed :
# None
# max_hits_displayed*
# create_all_hits_page*
#
# Output files :
# OUTPUT_ROOT/year/month/top_hits.html
@@ -34,6 +35,8 @@ class IWLADisplayTopHits(IPlugin):
super(IWLADisplayTopHits, self).__init__(iwla)
self.API_VERSION = 1
self.requires = ['IWLAPostAnalysisTopHits']
self.max_hits = self.iwla.getConfValue('max_hits_displayed', 0)
self.create_all_hits = self.iwla.getConfValue('create_all_hits_page', True)
def hook(self):
display = self.iwla.getDisplay()
@@ -41,23 +44,27 @@ class IWLADisplayTopHits(IPlugin):
top_hits = sorted(top_hits.items(), key=lambda t: t[1], reverse=True)
# All in a file
title = time.strftime('All Hits - %B %Y', self.iwla.getCurTime())
filename = 'top_hits.html'
path = self.iwla.getCurDisplayPath(filename)
if self.create_all_hits:
title = time.strftime('All Hits - %B %Y', self.iwla.getCurTime())
filename = 'top_hits.html'
path = self.iwla.getCurDisplayPath(filename)
page = display.createPage(title, path, self.iwla.getConfValue('css_path', []))
table = display.createBlock(DisplayHTMLBlockTable, 'All Hits', ['URI', 'Entrance'])
table.setColsCSSClass(['', 'iwla_hit'])
total_hits = [0]*2
for (uri, entrance) in top_hits:
table.appendRow([generateHTMLLink(uri), entrance])
total_hits[1] += entrance
page.appendBlock(table)
page = display.createPage(title, path, self.iwla.getConfValue('css_path', []))
table = display.createBlock(DisplayHTMLBlockTable, 'All Hits', ['URI', 'Entrance'])
table.setColsCSSClass(['', 'iwla_hit'])
total_hits = [0]*2
new_list = self.max_hits and top_hits[:self.max_hits] or top_hits
for (uri, entrance) in new_list:
table.appendRow([generateHTMLLink(uri), entrance])
total_hits[1] += entrance
page.appendBlock(table)
display.addPage(page)
display.addPage(page)
link = '<a href=\'%s\'>All hits</a>' % (filename)
title = '%s - %s' % ('Top Hits', link)
title = 'Top Hits'
if self.create_all_hits:
link = '<a href=\'%s\'>All Hits</a>' % (filename)
title = '%s - %s' % (title, link)
# Top in index
index = self.iwla.getDisplayIndex()