Fix presentation problems

This commit is contained in:
Grégory Soutadé 2014-12-04 19:15:15 +01:00
parent 897f96232c
commit 5f72a9c912
3 changed files with 39 additions and 36 deletions

View File

@ -146,7 +146,7 @@ class DisplayHTMLBlockTable(DisplayHTMLBlock):
class DisplayHTMLBlockTableWithGraph(DisplayHTMLBlockTable): class DisplayHTMLBlockTableWithGraph(DisplayHTMLBlockTable):
def __init__(self, title, cols, short_titles=None, nb_valid_rows=0): def __init__(self, title, cols, short_titles=None, nb_valid_rows=0, graph_cols=None):
super(DisplayHTMLBlockTableWithGraph, self).__init__(title=title, cols=cols) super(DisplayHTMLBlockTableWithGraph, self).__init__(title=title, cols=cols)
self.short_titles = short_titles or [] self.short_titles = short_titles or []
self.nb_valid_rows = nb_valid_rows self.nb_valid_rows = nb_valid_rows
@ -156,6 +156,8 @@ class DisplayHTMLBlockTableWithGraph(DisplayHTMLBlockTable):
self.raw_rows = [] self.raw_rows = []
self.maxes = [0] * len(cols) self.maxes = [0] * len(cols)
self.table_graph_css = 'iwla_graph_table' self.table_graph_css = 'iwla_graph_table'
self.td_img_css = 'iwla_td_img'
self.graph_cols = graph_cols or []
def appendRow(self, row): def appendRow(self, row):
self.raw_rows.append(row) self.raw_rows.append(row)
@ -196,8 +198,10 @@ class DisplayHTMLBlockTableWithGraph(DisplayHTMLBlockTable):
html += '<tr>' html += '<tr>'
for i in range(0, self.nb_valid_rows): for i in range(0, self.nb_valid_rows):
row = self.rows[i] row = self.rows[i]
html += '<td>' css = ''
for j in range(1, len(row)): if self.td_img_css: css=' class="%s"' % (self.td_img_css)
html += '<td%s>' % (css)
for j in self.graph_cols:
style = self.getColCSSClass(j) style = self.getColCSSClass(j)
icon = self._getIconFromStyle(style) icon = self._getIconFromStyle(style)
if not icon: continue if not icon: continue

61
iwla.py
View File

@ -245,13 +245,13 @@ class IWLA(object):
page = DisplayHTMLPage(title, filename, conf.css_path) page = DisplayHTMLPage(title, filename, conf.css_path)
_, nb_month_days = monthrange(cur_time.tm_year, cur_time.tm_mon) _, nb_month_days = monthrange(cur_time.tm_year, cur_time.tm_mon)
days = DisplayHTMLBlockTableWithGraph('By day', ['Day', 'Visitors', 'Pages', 'Hits', 'Bandwidth', 'Not viewed Bandwidth'], nb_valid_rows=nb_month_days) days = DisplayHTMLBlockTableWithGraph('By day', ['Day', 'Visitors', 'Pages', 'Hits', 'Bandwidth', 'Not viewed Bandwidth'], nb_valid_rows=nb_month_days, graph_cols=range(1,6))
days.setColsCSSClass(['', 'iwla_visitor', 'iwla_page', 'iwla_hit', 'iwla_bandwidth', 'iwla_bandwidth']) days.setColsCSSClass(['', 'iwla_visitor', 'iwla_page', 'iwla_hit', 'iwla_bandwidth', 'iwla_bandwidth'])
nb_visits = 0 nb_visits = 0
nb_days = 0 nb_days = 0
for i in range(0, nb_month_days): for i in range(1, nb_month_days+1):
day = '%d<br/>%s' % (i+1, time.strftime('%b', cur_time)) day = '%d<br/>%s' % (i, time.strftime('%b', cur_time))
full_day = '%d %s %d' % (i+1, time.strftime('%b', cur_time), cur_time.tm_year) full_day = '%d %s %d' % (i, time.strftime('%b', cur_time), cur_time.tm_year)
if i in self.current_analysis['days_stats'].keys(): if i in self.current_analysis['days_stats'].keys():
stats = self.current_analysis['days_stats'][i] stats = self.current_analysis['days_stats'][i]
row = [full_day, stats['nb_visitors'], stats['viewed_pages'], stats['viewed_hits'], row = [full_day, stats['nb_visitors'], stats['viewed_pages'], stats['viewed_hits'],
@ -261,18 +261,18 @@ class IWLA(object):
else: else:
row = [full_day, 0, 0, 0, 0, 0] row = [full_day, 0, 0, 0, 0, 0]
days.appendRow(row) days.appendRow(row)
days.setCellValue(i, 4, bytesToStr(row[4])) days.setCellValue(i-1, 4, bytesToStr(row[4]))
days.setCellValue(i, 5, bytesToStr(row[5])) days.setCellValue(i-1, 5, bytesToStr(row[5]))
days.appendShortTitle(day) days.appendShortTitle(day)
adate = date(cur_time.tm_year, cur_time.tm_mon, i+1) adate = date(cur_time.tm_year, cur_time.tm_mon, i)
week_day = adate.weekday() week_day = adate.weekday()
if week_day == 5 or week_day == 6: if week_day == 5 or week_day == 6:
days.setRowCSSClass(i, 'iwla_weekend') days.setRowCSSClass(i-1, 'iwla_weekend')
if adate == date.today(): if adate == date.today():
css = days.getCellCSSClass(i, 0) css = days.getCellCSSClass(i, 0)
if css: css = '%s %s' % (css, 'iwla_curday') if css: css = '%s %s' % (css, 'iwla_curday')
else: css = 'iwla_curday' else: css = 'iwla_curday'
days.setCellCSSClass(i, 0, css) days.setCellCSSClass(i-1, 0, css)
stats = self.current_analysis['month_stats'] stats = self.current_analysis['month_stats']
@ -295,36 +295,35 @@ class IWLA(object):
self.display.addPage(page) self.display.addPage(page)
def _generateDisplayMonthStats(self, page, year, month_stats): def _generateDisplayMonthStats(self, page, year, month_stats):
cur_time = time.localtime()
months_name = ['', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'June', 'July', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
title = 'Summary %d' % (year) title = 'Summary %d' % (year)
cols = ['Month', 'Visitors', 'Pages', 'Hits', 'Bandwidth', 'Not viewed Bandwidth'] cols = ['Month', 'Visitors', 'Pages', 'Hits', 'Bandwidth', 'Not viewed Bandwidth', 'Details']
months = DisplayHTMLBlockTableWithGraph(title, cols, nb_valid_rows=12) graph_cols=range(1,6)
months.setColsCSSClass(['', 'iwla_visit', 'iwla_page', 'iwla_hit', 'iwla_bandwidth', 'iwla_bandwidth']) months = DisplayHTMLBlockTableWithGraph(title, cols, nb_valid_rows=12, graph_cols=graph_cols)
months.setColsCSSClass(['', 'iwla_visit', 'iwla_page', 'iwla_hit', 'iwla_bandwidth', 'iwla_bandwidth', ''])
total = [0] * len(cols) total = [0] * len(cols)
for i in range(0, 12): for i in range(1, 13):
month = '%s<br/>%d' % ('Jan', year) month = '%s<br/>%d' % (months_name[i], year)
full_month = '%s %d' % ('Jan', year) full_month = '%s %d' % (months_name[i], year)
if i in month_stats.keys(): if i in month_stats.keys():
stats = month_stats[i] stats = month_stats[i]
link = '<a href="%d/%d/index.html">Details</a>' % (year, i)
row = [full_month, stats['nb_visitors'], stats['viewed_pages'], stats['viewed_hits'], row = [full_month, stats['nb_visitors'], stats['viewed_pages'], stats['viewed_hits'],
stats['viewed_bandwidth'], stats['not_viewed_bandwidth']] stats['viewed_bandwidth'], stats['not_viewed_bandwidth'], link]
for i in range(1, len(row[1:])): for j in graph_cols:
total[i] += row[i] total[j] += row[j]
else: else:
row = [full_month, 0, 0, 0, 0, 0] row = [full_month, 0, 0, 0, 0, 0, '']
months.appendRow(row) months.appendRow(row)
months.setCellValue(i, 4, bytesToStr(row[4])) months.setCellValue(i-1, 4, bytesToStr(row[4]))
months.setCellValue(i, 5, bytesToStr(row[5])) months.setCellValue(i-1, 5, bytesToStr(row[5]))
months.appendShortTitle(month) months.appendShortTitle(month)
# adate = date(cur_time.tm_year, cur_time.tm_mon, i+1) if year == cur_time.tm_year and i == cur_time.tm_mon:
# week_day = adate.weekday() css = months.getCellCSSClass(i-1, 0)
# if week_day == 5 or week_day == 6: if css: css = '%s %s' % (css, 'iwla_curday')
# months.setRowCSSClass(i, 'iwla_weekend') else: css = 'iwla_curday'
# if adate == date.today(): months.setCellCSSClass(i-1, 0, css)
# css = months.getCellCSSClass(i, 0)
# if css: css = '%s %s' % (css, 'iwla_curday')
# else: css = 'iwla_curday'
# months.setCellCSSClass(i, 0, css)
total[0] = 'Total' total[0] = 'Total'
total[4] = bytesToStr(total[4]) total[4] = bytesToStr(total[4])

View File

@ -20,7 +20,7 @@ body
width: 60%; width: 60%;
} }
.iwla_block_title > a a
{ {
font: 11px verdana, arial, helvetica, sans-serif; font: 11px verdana, arial, helvetica, sans-serif;
font-weight: normal; font-weight: normal;
@ -49,7 +49,7 @@ td
vertical-align:middle; vertical-align:middle;
} }
td img .iwla_td_img
{ {
vertical-align:bottom; vertical-align:bottom;
} }