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_downloads
#
# Conf values needed :
# None
# max_downloads_displayed*
# create_all_downloads_page*
#
# Output files :
# OUTPUT_ROOT/year/month/top_downloads.html
@@ -34,6 +35,8 @@ class IWLADisplayTopDownloads(IPlugin):
super(IWLADisplayTopDownloads, self).__init__(iwla)
self.API_VERSION = 1
self.requires = ['IWLAPostAnalysisTopDownloads']
self.max_downloads = self.iwla.getConfValue('max_downloads_displayed', 0)
self.create_all_downloads = self.iwla.getConfValue('create_all_downloads_page', True)
def hook(self):
display = self.iwla.getDisplay()
@@ -41,24 +44,28 @@ class IWLADisplayTopDownloads(IPlugin):
top_downloads = sorted(top_downloads.items(), key=lambda t: t[1], reverse=True)
# All in a file
filename = 'top_downloads.html'
path = self.iwla.getCurDisplayPath(filename)
title = time.strftime('All Downloads - %B %Y', self.iwla.getCurTime())
if self.create_all_downloads:
filename = 'top_downloads.html'
path = self.iwla.getCurDisplayPath(filename)
title = time.strftime('All Downloads - %B %Y', self.iwla.getCurTime())
page = display.createPage(title, path, self.iwla.getConfValue('css_path', []))
table = display.createBlock(DisplayHTMLBlockTable, 'All Downloads', ['URI', 'Hit'])
table.setColsCSSClass(['', 'iwla_hit'])
page = display.createPage(title, path, self.iwla.getConfValue('css_path', []))
table = display.createBlock(DisplayHTMLBlockTable, 'All Downloads', ['URI', 'Hit'])
table.setColsCSSClass(['', 'iwla_hit'])
total_entrance = [0]*2
for (uri, entrance) in top_downloads:
table.appendRow([generateHTMLLink(uri), entrance])
total_entrance[1] += entrance
page.appendBlock(table)
total_entrance = [0]*2
new_list = self.max_downloads and top_downloads[:self.max_downloads] or top_downloads
for (uri, entrance) in new_list:
table.appendRow([generateHTMLLink(uri), entrance])
total_entrance[1] += entrance
page.appendBlock(table)
display.addPage(page)
display.addPage(page)
link = '<a href=\'%s\'>All Downloads</a>' % (filename)
title = '%s - %s' % ('Top Downloads', link)
title = 'Top Downloads'
if self.create_all_downloads:
link = '<a href=\'%s\'>All Downloads</a>' % (filename)
title = '%s - %s' % (title, link)
# Top in index
index = self.iwla.getDisplayIndex()