/
erudition.py
executable file
·141 lines (119 loc) · 3.99 KB
/
erudition.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
#!/usr/bin/python
# IMPORTS:
import cgi
import cgitb
cgitb.enable()
import base, settings
from connect import connect
# :IMPORTS
# FUNCTIONS:
def fetch_test_info(db):
# Connect to DB:
con = connect(False, db)
cur = con.cursor()
# Fetch from DB:
cur.execute("SELECT name, desc_long, required, relative_order FROM Test_Type")
rows = cur.fetchall()
# Return:
return sorted([{'name':test[0], 'desc':test[1], 'req':test[2], "order":test[3]} for test in rows], key=lambda k: k["order"])
def fetch_card_info(db):
# Connect to DB:
con = connect(False, db)
cur = con.cursor()
# Fetch from DB:
cur.execute("SELECT info_type_id, Info_Name, Info_Desc_Short, Info_Desc_Long FROM Card_Info_Types")
rows = cur.fetchall()
# Return:
return sorted([{'id':info[0], 'name':info[1], 'short':info[2], "long":info[3]} for info in rows], key=lambda k: k["id"])
def print_test_info_table(db):
print '<div class="row">'
print '<div class="col-md-12">'
print '<center><h3>Test information</h3></center>'
print '<table class="table" id="testInfoTable" style="width:100%">'
print '<tbody>'
print '<tr>'
print '<th>Test name</th>'
print '<th>Description</th>'
print '<th>Required?</th>'
print '</tr>'
testInfo = fetch_test_info(db)
for test in testInfo:
print '<tr align=left>'
print u'<td>{0}</td>'.format(test['name']).encode('utf-8')
print u'<td>{0}</td>'.format(test['desc']).encode('utf-8')
if test['req'] == 0 :
print '<td>no</td>'
else:
print '<td>yes</td>'
print '</tr>'
print '</tbody>'
print '</table>'
print '</div>'
print '</div>'
def print_card_info_table(db):
card_infos = fetch_card_info(db)
print '<div class="row">'
print '<div class="col-md-12">'
print '<center><h3>Module information</h3></center>'
if (card_infos):
print '<table class="table" id="cardInfoTable" style="width:100%">'
print '<tbody>'
print '<tr>'
print '<th>Characteristic</th>'
print '<th>Description</th>'
print '</tr>'
for card_info in card_infos:
print '<tr align=left>'
print u'<td>{0}</td>'.format(card_info['name']).encode('utf-8')
print u'<td>{0}</td>'.format(card_info['long']).encode('utf-8')
print '</tr>'
print '</tbody>'
print '</table>'
print '</div>'
print '</div>'
else:
print '<center><p><i>No module information.</i></p></center>'
def print_testtype_form(db):
print '<div class="row"><form action="add_testtype.py?db={0}" method="post" enctype="multipart/form-data">'.format(db)
print '\t<div class="col-md-6">'
print '\t\t<b>Add test type:</b><br>'
print '\t\tName:<br>'
print '\t\t<input type="text" name="testName"><br><br>'
print '\t\tDescribe the test in brief:<br>'
print '\t\t<textarea name="descShort" rows="5" cols="50"></textarea><br><br>'
print '\t\tDescribe the test at length:<br>'
print '\t\t<textarea name="descLong" rows="5" cols="100"></textarea><br><br>'
print '\t\t<input type="checkbox" name="required" checked="checked">Required<br><br>'
print '\t\t<input type="submit" value="Submit"><br><br>'
print '\t</div>'
print '</form></div>'
def print_cardinfotype_form(db):
print '<div class="row"><form action="add_cardInfoType.py?db={0}" method="post" enctype="multipart/form-data">'.format(db)
print '\t<div class="col-md-6">'
print '\t\t<b>Add characteristic type:</b><br>'
print '\t\tName:<br>'
print '\t\t<input type="text" name="characteristic"><br><br>'
print '\t\tDescribe the characteristic in brief:<br>'
print '\t\t<textarea name="descShort" rows="5" cols="50"></textarea><br><br>'
print '\t\tDescribe the characteristic at length:<br>'
print '\t\t<textarea name="descLong" rows="5" cols="100"></textarea><br><br>'
print '\t\t<input type="submit" value="Submit"><br><br>'
print '\t</div>'
print '</form></div>'
def main():
db = settings.get_db()
base.begin()
base.header(title='{0}: tests'.format(db))
base.top(db)
print_test_info_table(db)
print '<br><br>'
print_testtype_form(db)
print_card_info_table(db)
print '<br><br>'
print_cardinfotype_form(db)
base.bottom()
# :FUNCTIONS
# MAIN:
if __name__ == "__main__":
main()
# :MAIN