-
Notifications
You must be signed in to change notification settings - Fork 0
/
genHTML.py
150 lines (140 loc) · 4.69 KB
/
genHTML.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
import connectToDatabase
import login
__author__ = 'WS02admin'
def genHTTPHeader():
header ="""\
Content-Type: text/html
"""
return header
def genPageHeader(title):
return """\
<!DOCTYPE html>
<html>
<head>
<title> %(title)s</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
<style>
body{
padding-top:60px;
}
</style>
<link href="bootstrap/css/bootstrap-responsive.min.css" rel="stylesheet">
</head>
<body>
""" % {'title': title}
def genMenuBar(title, links, token):
menuString = """\
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a class="brand" href="%(base)sindex.py">%(title)s</a>
<div class="nav-collapse">
<ul class="nav">
""" % {'title':title, 'base':connectToDatabase.getDirBase()}
for l in links:
menuString += ("""\
<li %(activeClass)s><a href=\"%(link)s\">%(name)s</a></li>""") \
% {'link': l['link'],'name':l['name'], 'activeClass':'class="active"' if l['active'] else ''}
if login.isLoggedIn(token):
menuString += """\
</ul>
<ul class="nav pull-right">
<li>
<form action="search.py" method="GET" name='search' class="navbar-search">
<input type="text" name="search" placeholder="Search" class="search-query span2">
</form>
</li>
<li class="divider-vertical"></li>
<li class="dropdown">
<a data-toggle="dropdown" class="dropdown-toggle" href="#">%(name)s<b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="logout.py">Log Out</a></li>
</ul>
</li>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
</div>
""" % {'name':login.getName(token)}
else:
menuString += """\
</ul>
<ul class="nav pull-right">
<li><a href="login.py">Log In</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
</div>
"""
return menuString
def beginContainer():
return ' <div class="container">\n'
def endContainer():
return ' </div>\n'
def genPageFooter():
return """\
<script src="js/jquery.min.js"></script>
<script src="bootstrap/js/bootstrap.min.js"></script>
</body>
</html>
"""
def genPagination(noPages, base, activePage):
string = ''
if noPages > 1:
pageNumbers = []
if noPages > 11 and activePage - 5 >= 0:
pageNumbers.append(0)
pageNumbers.append(1)
pageNumbers.append(-1)
if not activePage+2 < noPages:
pageNumbers.append(activePage-4)
if not activePage+1 < noPages:
pageNumbers.append(activePage-3)
pageNumbers.append(activePage-2)
pageNumbers.append(activePage-1)
pageNumbers.append(activePage)
if activePage+1 < noPages:
pageNumbers.append(activePage+1)
if activePage+2 < noPages:
pageNumbers.append(activePage+2)
elif noPages > 11:
pageNumbers.append(0)
pageNumbers.append(1)
pageNumbers.append(2)
pageNumbers.append(3)
pageNumbers.append(4)
pageNumbers.append(5)
pageNumbers.append(6)
pageNumbers.append(7)
else:
for i in range(0,noPages):
pageNumbers.append(i)
if noPages > 11 and activePage + 6 <= noPages:
pageNumbers.append(-1)
pageNumbers.append(noPages-2)
pageNumbers.append(noPages-1)
elif noPages > 11:
for i in range(activePage+3,noPages):
pageNumbers.append(i)
string += """\
<div class="pagination pagination-centered">
<ul>
<li %(class)s><a href="%(base)s&pagenum=%(activePageMinus1)s">‹</a></li>
""" % {'class':'' if activePage!=0 else 'class="disabled"', 'base':base,'activePageMinus1': str(activePage)}
for i in pageNumbers:
string+= """\
<li %(class)s><a href="%(base)s&pagenum=%(ip)s">%(i)s</a></li>
""" % {'class':'' if i != activePage and ( i>=0 and i<noPages) else('class="disabled"' if i <0 else'class=active'),
'base':base,'ip': str(i) if i>=0 else activePage, 'i': str(i + 1) if i>=0 else '…',
}
string += """\
<li %(class)s><a href="%(base)s&pagenum=%(activePagePlus1)s">›</a></li>
</ul>
</div>
""" % {'class':'' if activePage<(noPages-1) else 'class="disabled"', 'base':base,'activePagePlus1': str(activePage+2)}
return string