iwla

iwla Commit Details

Date:2014-11-27 19:38:41 (6 years 8 months ago)
Author:Grégory Soutadé
Branch:dev, master
Commit:d2b0d0dae6e4851c367b34310315d9cec264d3de
Parents: 02233f2f37f7e03e621006e0b3768dd30fb12653
Message:Fully rework display with CSS style inclusion

Changes:
Mdisplay.py (3 diffs)
Mplugins/display/all_visits.py (1 diff)
Mplugins/display/referers.py (3 diffs)
Mplugins/display/top_downloads.py (2 diffs)
Mplugins/display/top_hits.py (1 diff)
Mplugins/display/top_pages.py (1 diff)

File differences

display.py
11
22
3
3
44
5
6
5
6
7
8
9
710
11
12
13
814
9
15
1016
11
17
1218
1319
14
15
20
21
22
23
24
1625
17
18
26
27
28
29
30
31
32
33
34
35
36
37
38
39
1940
2041
21
42
43
44
45
46
47
48
2249
2350
2451
2552
26
53
2754
2855
56
57
2958
3059
3160
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
3276
77
78
79
80
81
82
83
84
85
86
87
88
89
90
3391
34
35
36
37
38
39
40
41
42
43
44
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
45107
46108
47109
......
53115
54116
55117
118
119
120
121
122
123
56124
57125
58126
......
64132
65133
66134
67
135
136
137
138
139
140
141
68142
69143
70144
import os
class DisplayHTMLBlock(object):
class DisplayHTMLRaw(object):
def __init__(self, title=''):
self.title = title
def __init__(self, html=''):
self.html = html
def setRawHTML(self, html):
self.html = html
def _build(self, f, html):
if html: f.write(html)
def build(self, f):
pass
self._build(self.html)
class DisplayHTMLRawBlock(DisplayHTMLBlock):
class DisplayHTMLBlock(DisplayHTMLRaw):
def __init__(self, title=''):
super(DisplayHTMLRawBlock, self).__init__(title)
self.html = ''
super(DisplayHTMLBlock, self).__init__(html='')
self.title = title
self.cssclass = 'iwla_block'
self.title_cssclass = 'iwla_block_title'
self.value_cssclass = 'iwla_block_value'
def setRawHTML(self, html):
self.html = html
def getTitle(self):
return self.title
def setTitle(self, value):
self.title = value
def setCSSClass(self, cssclass):
self.cssclass = cssclass
def setTitleCSSClass(self, cssclass):
self.title_cssclass = cssclass
def setValueCSSClass(self, cssclass):
self.value_cssclass = cssclass
def build(self, f):
f.write(self.html)
html = '<div class="%s">' % (self.cssclass)
if self.title:
html += '<div class="%s">%s</div>' % (self.title_cssclass, self.title)
html += '<div class="%s">%s</div>' % (self.value_cssclass, self.html)
html += '</div>'
self._build(f, html)
class DisplayHTMLBlockTable(DisplayHTMLBlock):
def __init__(self, title, cols):
super(DisplayHTMLBlockTable, self).__init__(title)
super(DisplayHTMLBlockTable, self).__init__(title=title)
self.cols = cols
self.rows = []
self.cols_cssclasses = ['' for e in cols]
self.rows_cssclasses = []
def appendRow(self, row):
self.rows.append(listToStr(row))
self.rows_cssclasses.append(['' for e in row])
def getCellValue(row, col):
if row < 0 or col < 0 or\
row >= len(self.rows) or col >= len(self.cols):
raise ValueError('Invalid indices')
return self.rows[row][col]
def setCellValue(row, col, value):
if row < 0 or col < 0 or\
row >= len(self.rows) or col >= len(self.cols):
raise ValueError('Invalid indices')
return self.rows[row][col]
def setCellCSSClass(row, col, value):
if row < 0 or col < 0 or\
row >= len(self.rows) or col >= len(self.cols):
raise ValueError('Invalid indices')
self.rows_cssclasses[row][col] = value
def setRowCSSClass(row, value):
if row < 0 or row >= len(self.rows):
raise ValueError('Invalid indice')
for i in range(0, self.rows_cssclasses[row]):
self.rows_cssclasses[row][i] = value
def build(self, f):
f.write('<table>')
f.write('<tr>')
for title in self.cols:
f.write('<th>%s</th>' % (title))
f.write('</tr>')
for row in self.rows:
f.write('<tr>')
for v in row:
f.write('<td>%s</td>' % (v))
f.write('</tr>')
f.write('</table>')
if not self.html:
html = '<table>'
html += '<tr>'
for title in self.cols:
html += '<th>%s</th>' % (title)
html += '</tr>'
for row in self.rows:
html += '<tr>'
for v in row:
html += '<td>%s</td>' % (v)
html += '</tr>'
html += '</table>'
self.html = html
super(DisplayHTMLBlockTable, self).build(f)
class DisplayHTMLPage(object):
def getFilename(self):
return self.filename;
def getBlock(self, title):
for b in self.blocks:
if title == b.getTitle():
return b
return None
def appendBlock(self, block):
self.blocks.append(block)
os.makedirs(base)
f = open(filename, 'w')
f.write('<html><title>%s</title><body>' % (self.title))
f.write('<!DOCTYPE html>')
f.write('<html>')
f.write('<head>')
f.write('<meta http-equiv="Content-type" content="text/html; charset=UTF-8" />')
if self.title:
f.write('<title>%s</title>' % (self.title))
f.write('</head>')
for block in self.blocks:
block.build(f)
f.write('</body></html>')
plugins/display/all_visits.py
4242
4343
4444
45
46
47
45
46
47
48
49
50
51
52
display.addPage(page)
index = self.iwla.getDisplayIndex()
block = DisplayHTMLRawBlock()
block.setRawHTML('<a href=\'%s\'>All visits</a>' % (filename))
index.appendBlock(block)
link = '<a href=\'%s\'>All visits</a>' % (filename)
block = index.getBlock('Top visitors')
if block:
block.setTitle('%s - %s' % (block.getTitle(), link))
else:
block = DisplayHTMLRawBlock()
block.setRawHTML(link)
index.appendBlock(block)
plugins/display/referers.py
2929
3030
3131
32
32
3333
3434
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
5335
54
5536
5637
5738
......
8061
8162
8263
83
84
85
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
8684
87
88
89
90
9185
9286
9387
......
10498
10599
106100
107
108
109
101
102
103
104
105
106
107
108
top_key_phrases = key_phrases.items()
top_key_phrases = sorted(top_key_phrases, key=lambda t: t[1], reverse=True)
# Top referers in index
cur_time = self.iwla.getCurTime()
index = self.iwla.getDisplayIndex()
table = DisplayHTMLBlockTable('Connexion from', ['Origin', 'Pages', 'Hits'])
table.appendRow(['<b>Search Engine</b>', '', ''])
for r,_ in top_search_engine_referers[:10]:
row = [r, search_engine_referers[r]['pages'], search_engine_referers[r]['hits']]
table.appendRow(row)
table.appendRow(['<b>External URL</b>', '', ''])
for r,_ in top_referers[:10]:
row = [r, referers[r]['pages'], referers[r]['hits']]
table.appendRow(row)
table.appendRow(['<b>External URL (robot)</b>', '', ''])
for r,_ in top_robots_referers[:10]:
row = [r, robots_referers[r]['pages'], robots_referers[r]['hits']]
table.appendRow(row)
index.appendBlock(table)
# All referers in a file
cur_time = self.iwla.getCurTime()
title = time.strftime('Connexion from - %B %Y', cur_time)
filename = 'referers.html'
display = self.iwla.getDisplay()
display.addPage(page)
block = DisplayHTMLRawBlock()
block.setRawHTML('<a href=\'%s\'>All referers</a>' % (filename))
index.appendBlock(block)
link = '<a href=\'%s\'>All referers</a>' % (filename)
# Top referers in index
title = '%s - %s' % ('Connexion from', link)
table = DisplayHTMLBlockTable(title, ['Origin', 'Pages', 'Hits'])
table.appendRow(['<b>Search Engine</b>', '', ''])
for r,_ in top_search_engine_referers[:10]:
row = [r, search_engine_referers[r]['pages'], search_engine_referers[r]['hits']]
table.appendRow(row)
table.appendRow(['<b>External URL</b>', '', ''])
for r,_ in top_referers[:10]:
row = [r, referers[r]['pages'], referers[r]['hits']]
table.appendRow(row)
table.appendRow(['<b>External URL (robot)</b>', '', ''])
for r,_ in top_robots_referers[:10]:
row = [r, robots_referers[r]['pages'], robots_referers[r]['hits']]
table.appendRow(row)
# Top key phrases in index
table = DisplayHTMLBlockTable('Top key phrases', ['Key phrase', 'Search'])
for phrase in top_key_phrases[:10]:
table.appendRow([phrase[0], phrase[1]])
index.appendBlock(table)
# All key phrases in a file
display.addPage(page)
block = DisplayHTMLRawBlock()
block.setRawHTML('<a href=\'%s\'>All key phrases</a>' % (filename))
index.appendBlock(block)
link = '<a href=\'%s\'>All key phrases</a>' % (filename)
# Top key phrases in index
title = '%s - %s' % ('Top key phrases', link)
table = DisplayHTMLBlockTable(title, ['Key phrase', 'Search'])
for phrase in top_key_phrases[:10]:
table.appendRow([phrase[0], phrase[1]])
index.appendBlock(table)
plugins/display/top_downloads.py
1212
1313
1414
15
1615
1716
18
19
20
21
22
23
24
25
26
17
2718
2819
20
2921
3022
3123
......
3325
3426
3527
36
37
28
29
30
31
3832
39
40
41
33
34
35
36
37
38
39
def hook(self):
top_downloads = self.iwla.getMonthStats()['top_downloads']
top_downloads = sorted(top_downloads.items(), key=lambda t: t[1], reverse=True)
index = self.iwla.getDisplayIndex()
table = DisplayHTMLBlockTable('Top Downloads', ['URI', 'Hits'])
for (uri, entrance) in top_downloads[:10]:
table.appendRow([uri, entrance])
index.appendBlock(table)
title = time.strftime('Top Downloads - %B %Y', self.iwla.getCurTime())
# All in a file
filename = 'top_downloads.html'
path = self.iwla.getCurDisplayPath(filename)
title = time.strftime('All Downloads - %B %Y', self.iwla.getCurTime())
page = DisplayHTMLPage(title, path)
table = DisplayHTMLBlockTable('All Downloads', ['URI', 'Hit'])
table.appendRow([uri, entrance])
page.appendBlock(table)
display = self.iwla.getDisplay()
display.addPage(page)
self.iwla.getDisplay().addPage(page)
link = '<a href=\'%s\'>All Downloads</a>' % (filename)
title = '%s - %s' % ('Top Downloads', link)
block = DisplayHTMLRawBlock()
block.setRawHTML('<a href=\'%s\'>All Downloads</a>' % (filename))
index.appendBlock(block)
# Top in index
index = self.iwla.getDisplayIndex()
table = DisplayHTMLBlockTable(title, ['URI', 'Hits'])
for (uri, entrance) in top_downloads[:10]:
table.appendRow([uri, entrance])
index.appendBlock(table)
plugins/display/top_hits.py
1212
1313
1414
15
1615
1716
18
19
20
21
22
23
24
17
2518
26
2719
2820
2921
3022
31
23
3224
3325
3426
3527
36
37
28
29
30
31
3832
39
40
41
33
34
35
36
37
38
39
def hook(self):
top_hits = self.iwla.getMonthStats()['top_hits']
top_hits = sorted(top_hits.items(), key=lambda t: t[1], reverse=True)
index = self.iwla.getDisplayIndex()
table = DisplayHTMLBlockTable('Top Hits', ['URI', 'Entrance'])
for (uri, entrance) in top_hits[:10]:
table.appendRow([uri, entrance])
index.appendBlock(table)
# All in a file
title = time.strftime('All Hits - %B %Y', self.iwla.getCurTime())
filename = 'top_hits.html'
path = self.iwla.getCurDisplayPath(filename)
page = DisplayHTMLPage(title, path)
table = DisplayHTMLBlockTable('Top Hits', ['URI', 'Entrance'])
table = DisplayHTMLBlockTable('All Hits', ['URI', 'Entrance'])
for (uri, entrance) in top_hits:
table.appendRow([uri, entrance])
page.appendBlock(table)
display = self.iwla.getDisplay()
display.addPage(page)
self.iwla.getDisplay().addPage(page)
link = '<a href=\'%s\'>All hits</a>' % (filename)
title = '%s - %s' % ('Top Hits', link)
block = DisplayHTMLRawBlock()
block.setRawHTML('<a href=\'%s\'>All hits</a>' % (filename))
index.appendBlock(block)
# Top in index
index = self.iwla.getDisplayIndex()
table = DisplayHTMLBlockTable(title, ['URI', 'Entrance'])
for (uri, entrance) in top_hits[:10]:
table.appendRow([uri, entrance])
index.appendBlock(table)
plugins/display/top_pages.py
1212
1313
1414
15
1615
1716
18
19
20
21
22
23
24
17
2518
26
2719
2820
2921
3022
31
23
3224
3325
3426
3527
36
37
28
29
30
31
3832
39
40
41
33
34
35
36
37
38
39
def hook(self):
top_pages = self.iwla.getMonthStats()['top_pages']
top_pages = sorted(top_pages.items(), key=lambda t: t[1], reverse=True)
index = self.iwla.getDisplayIndex()
table = DisplayHTMLBlockTable('Top Pages', ['URI', 'Entrance'])
for (uri, entrance) in top_pages[:10]:
table.appendRow([uri, entrance])
index.appendBlock(table)
# All in a page
title = time.strftime('All Pages - %B %Y', self.iwla.getCurTime())
filename = 'top_pages.html'
path = self.iwla.getCurDisplayPath(filename)
page = DisplayHTMLPage(title, path)
table = DisplayHTMLBlockTable('Top Pages', ['URI', 'Entrance'])
table = DisplayHTMLBlockTable('All Pages', ['URI', 'Entrance'])
for (uri, entrance) in top_pages:
table.appendRow([uri, entrance])
page.appendBlock(table)
display = self.iwla.getDisplay()
display.addPage(page)
self.iwla.getDisplay().addPage(page)
link = '<a href=\'%s\'>All pages</a>' % (filename)
title = '%s - %s' % ('Top Pages', link)
block = DisplayHTMLRawBlock()
block.setRawHTML('<a href=\'%s\'>All pages</a>' % (filename))
index.appendBlock(block)
# Top in index
index = self.iwla.getDisplayIndex()
table = DisplayHTMLBlockTable(title, ['URI', 'Entrance'])
for (uri, entrance) in top_pages[:10]:
table.appendRow([uri, entrance])
index.appendBlock(table)

Archive Download the corresponding diff file

Branches

Tags