BaseViewier 0.1.1

 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
import string, MySQLdb, mod_python
def replace_tmpl(tmpl, var_list):
lines = open(tmpl).readlines()
src = "%s"*len(lines) % tuple(lines)
for key, var in var_list.items():
src = string.replace( src, key, var )
return src
def index(req):
db = MySQLdb.Connect(db='test_db',host='localhost',user='root', passwd='galka')
cursor = db.cursor()
#postname = req.form['username']
#passwd = req.form['password']
postname = 'detsad1619'
cursor.execute('SELECT org FROM users WHERE username="%s"' % postname)
searchTmpl = cursor.fetchall()[0][0]
cursor.execute('SELECT * FROM payments WHERE org RLIKE "%s"' % searchTmpl)
result = cursor.fetchall()
lineTmpl = '/var/www/line.tmpl'
body = ''
for row in result:
body = body + replace_tmpl(lineTmpl, {'$date$':str(row[0]),
'$session$':str(row[1]),
'$org$':str(row[2]),
'$sum$':str(row[3]),
'$name$':str(row[4])})
top = """\
<html>
<body>
<table align=center>
<tr>
<td>Date</td>
<td>Session</td>
<td>Organisation</td>
<td>Sum</td>
<td>Name</td>
</tr>
"""
#print body
bottom = """\
</table>
</body>
</html>"""
zz = top + body + bottom
return zz;