Mercurial > roundup-cc
comparison display_issues.py @ 24:89469aa41fe1
Preliminary work to make the display more dynamic.
* The values are now dynamically read from the database and written to a
dynamic dict.
* If "None" (NoPrio) is not existent it is set to [0] because the JS expects a
value.
author | Magnus Schieder <mschieder@intevation.de> |
---|---|
date | Fri, 02 Nov 2018 17:06:45 +0100 |
parents | 3bb3d9a9f1b7 |
children | 7161ce4e7ab1 |
comparison
equal
deleted
inserted
replaced
21:7a523e13fcb3 | 24:89469aa41fe1 |
---|---|
38 for item in array: | 38 for item in array: |
39 formated.append("{date : new Date('" + str(item) + "')}") | 39 formated.append("{date : new Date('" + str(item) + "')}") |
40 | 40 |
41 return ", ".join(formated) | 41 return ", ".join(formated) |
42 | 42 |
43 def get_webpage(status, keywords, graph=None): | 43 def get_webpage(data_dict, columns, status, keywords, graph=None): |
44 | 44 |
45 if graph is None: | 45 if graph is None: |
46 graph = os.path.dirname(os.path.realpath(__file__)) + '/graph.html' | 46 graph = os.path.dirname(os.path.realpath(__file__)) + '/graph.html' |
47 | 47 |
48 with open(graph, "r") as html_chart_file: | 48 with open(graph, "r") as html_chart_file: |
49 base_html_data = html_chart_file.read() | 49 base_html_data = html_chart_file.read() |
50 | 50 |
51 if "None" not in columns: | |
52 data_dict["None"] = [0] | |
51 | 53 |
52 base_html_data = (base_html_data | 54 base_html_data = (base_html_data |
53 .replace("status", status) | 55 .replace("status", status) |
54 .replace("keywords", keywords) | 56 .replace("keywords", keywords) |
55 .replace("var critical=[];", "var critical=[" + make_js_object_string(rcd.data_dict["critical"]) + "]") | 57 .replace("var critical=[];", "var critical=[" + make_js_object_string(data_dict["critical"]) + "]") |
56 .replace("var urgent=[];", "var urgent=[" + make_js_object_string(rcd.data_dict["urgent"]) + "]") | 58 .replace("var urgent=[];", "var urgent=[" + make_js_object_string(data_dict["urgent"]) + "]") |
57 .replace("var bug=[];", "var bug=[" + make_js_object_string(rcd.data_dict["bug"]) + "]") | 59 .replace("var bug=[];", "var bug=[" + make_js_object_string(data_dict["bug"]) + "]") |
58 .replace("var feature=[];", "var feature=[" + make_js_object_string(rcd.data_dict["feature"]) + "]") | 60 .replace("var feature=[];", "var feature=[" + make_js_object_string(data_dict["feature"]) + "]") |
59 .replace("var wish=[];", "var wish=[" + make_js_object_string(rcd.data_dict["wish"]) + "]") | 61 .replace("var wish=[];", "var wish=[" + make_js_object_string(data_dict["wish"]) + "]") |
60 .replace("var noPrio=[];", "var noPrio=[" + make_js_object_string(rcd.data_dict["noPrio"]) + "]") | 62 .replace("var noPrio=[];", "var noPrio=[" + make_js_object_string(data_dict["None"]) + "]") |
61 .replace("var timestamp=[];", "var timestamp=[" + make_js_object_date(rcd.data_dict["date"]) + "]")) | 63 .replace("var timestamp=[];", "var timestamp=[" + make_js_object_date(data_dict["date"]) + "]")) |
62 | 64 |
63 return base_html_data | 65 return base_html_data |
64 | 66 |
65 def compile_db_stats_html(db_file, sql_select, status="", keywords="", graph=None): | 67 def compile_db_stats_html(db_file, sql_select, columns, status="", keywords="", graph=None): |
68 | |
69 data_dict = {"date": []} | |
70 status_list = columns.split(", ") | |
71 for x in status_list: | |
72 data_dict[x] = [] | |
66 | 73 |
67 con = None | 74 con = None |
68 cur = None | 75 cur = None |
69 | 76 |
70 try: | 77 try: |
71 con = db.connect(db_file) | 78 con = db.connect(db_file) |
72 cur = con.cursor() | 79 cur = con.cursor() |
73 cur.execute(sql_select) | 80 cur.execute(sql_select) |
74 | 81 |
75 for row in cur.fetchall(): | 82 for row in cur.fetchall(): |
76 rcd.data_dict["date"].append(row[0]) | 83 data_dict["date"].append(row[0]) |
77 rcd.data_dict["critical"].append(row[1]) | 84 for x in range(len(status_list)): |
78 rcd.data_dict["urgent"].append(row[2]) | 85 data_dict[status_list[x]].append(row[x+1]) |
79 rcd.data_dict["bug"].append(row[3]) | 86 |
80 rcd.data_dict["feature"].append(row[4]) | |
81 rcd.data_dict["wish"].append(row[5]) | |
82 rcd.data_dict["noPrio"].append(row[6]) | |
83 finally: | 87 finally: |
84 if cur: | 88 if cur: |
85 cur.close() | 89 cur.close() |
86 if con: | 90 if con: |
87 con.close() | 91 con.close() |
88 | 92 |
89 return get_webpage(status, keywords, graph) | 93 return get_webpage(data_dict, columns, status, keywords, graph) |
90 | 94 |
91 def render_webpage(content): | 95 def render_webpage(content): |
92 for line in content.split("\n"): | 96 for line in content.split("\n"): |
93 print(line) | 97 print(line) |
94 | 98 |
95 def render_db_stats_as_html(db_file, sql_select, status="", keywords=""): | 99 def render_db_stats_as_html(db_file, sql_select, columns, status="", keywords=""): |
96 render_webpage(compile_db_stats_html(db_file, sql_select, status, keywords)) | 100 render_webpage(compile_db_stats_html(db_file, sql_select, columns, status, keywords)) |
97 | 101 |
98 if __name__ == '__main__': | 102 if __name__ == '__main__': |
99 cgitb.enable() | 103 cgitb.enable() |
100 #spit out HTML file directly, thus no need to give headers to the server | 104 #spit out HTML file directly, thus no need to give headers to the server |
101 #print("Content-Type: text/html") | 105 #print("Content-Type: text/html") |