This repository has been archived by the owner on Sep 4, 2019. It is now read-only.
/
statsview.py
151 lines (141 loc) · 5.58 KB
/
statsview.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
from main import *
class StatsViewBase(TemplatePage):
def generateContent(self):
output = []
output.append("""
<div class="tocbox">
<ul>
<li><a href="/bystats" title="Recent stats">All</a> </li>
<li><a href="/bystats-researchers" title="Recent stats for Researchers">Researchers</a>
</li>
<li><a href="/bystats-educators" title="Recent stats for Educators">Educators</a>
</li>
<li><a href="/bystats-artvis" title="Recent stats for Art, Visual">Art/Visual</a>
</li>
</ul>
</div>
<h2> The latests stats %(title)s </h2>
<table class="bydate" id="commentsperday">
<thead>
<tr>
<th align="left" class="datecolumn">
</th>
<th align="left" class="blogcolumn">
Comments last 24h
</th>
</tr>
</thead>
<tbody>"""% {'title':html_escape(self.selftitle)})
for feed in Feed.gql("WHERE category IN :1 ORDER BY comments_day DESC", self.categories()):
output.append("""
<tr>
<td valign="bottom" class="datecolumn">
%(comments_day)s
</td>
<td valign="bottom" class="blogcolumn">
<a href="%(homepage)s">%(title)s</a>
</td>
</tr>""" % {'comments_day': str(feed.comments_day), 'homepage': html_escape(feed.homepage), 'title': html_escape(feed.title) })
output.append("""
</tbody>
</table>""")
output.append("""
<table class="bydate" id="commentsperweek">
<thead>
<tr>
<th align="left" class="datecolumn">
</th>
<th align="left" class="blogcolumn">
Comments last week
</th>
</tr>
</thead>
<tbody>""")
for feed in Feed.gql("WHERE category IN :1 ORDER BY comments_week DESC", self.categories()):
output.append("""
<tr>
<td valign="bottom" class="datecolumn">
%(comments_week)s
</td>
<td valign="bottom" class="blogcolumn">
<a href="%(homepage)s">%(title)s</a>
</td>
</tr>""" % {'comments_week': str(feed.comments_week), 'homepage': html_escape(feed.homepage), 'title': html_escape(feed.title) })
output.append("""
</tbody>
</table>""")
output.append("""
<table class="bydate" id="postsperweek">
<thead>
<tr>
<th align="left" class="datecolumn">
</th>
<th align="left" class="blogcolumn">
Posts last week
</th>
</tr>
</thead>
<tbody>""")
for feed in Feed.gql("WHERE category IN :1 ORDER BY posts_week DESC", self.categories()):
output.append("""
<tr>
<td valign="bottom" class="datecolumn">
%(posts_week)s
</td>
<td valign="bottom" class="blogcolumn">
<a href="%(homepage)s">%(title)s</a>
</td>
</tr>""" % {'posts_week': str(feed.posts_week), 'homepage': html_escape(feed.homepage), 'title': html_escape(feed.title) })
output.append("""
</tbody>
</table>""")
output.append("""
<table class="bydate" id="postspermonth">
<thead>
<tr>
<th align="left" class="datecolumn">
</th>
<th align="left" class="blogcolumn">
Posts last month
</th>
</tr>
</thead>
<tbody>""")
for feed in Feed.gql("WHERE category IN :1 ORDER BY posts_month DESC", self.categories()):
output.append("""
<tr>
<td valign="bottom" class="datecolumn">
%(posts_month)s
</td>
<td valign="bottom" class="blogcolumn">
<a href="%(homepage)s">%(title)s</a>
</td>
</tr>""" % {'posts_month': str(feed.posts_month), 'homepage': html_escape(feed.homepage), 'title': html_escape(feed.title) })
output.append("""
</tbody>
</table>""")
return "".join(output)
class StatsView(StatsViewBase):
selfurl = "bystats"
selftitle = ""
cacheName = "StatsView"
def categories(self):
return ['history','fun','general','commercial','art','visual','pure','applied','teacher','journalism']
class StatsViewResearchers(StatsViewBase):
selfurl = "bystats-researchers"
selftitle = " for researchers"
cacheName = "StatsViewResearchers"
def categories(self):
return ['history','pure','applied','general']
class StatsViewEducators(StatsViewBase):
selfurl = "bystats-educators"
selftitle = " for educators"
cacheName = "StatsViewEducators"
def categories(self):
return ['teacher']
class StatsViewArtVis(StatsViewBase):
selfurl = "bystats-artvis"
selftitle = " for art and visual"
cacheName = "StatsViewArtVis"
def categories(self):
return ['art','visual']