Mercurial > roundup-cc
changeset 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 | 7a523e13fcb3 |
children | 7161ce4e7ab1 |
files | display_issues.py display_issues_demo.py |
diffstat | 2 files changed, 24 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/display_issues.py Tue Oct 23 13:06:16 2018 +0200 +++ b/display_issues.py Fri Nov 02 17:06:45 2018 +0100 @@ -40,7 +40,7 @@ return ", ".join(formated) -def get_webpage(status, keywords, graph=None): +def get_webpage(data_dict, columns, status, keywords, graph=None): if graph is None: graph = os.path.dirname(os.path.realpath(__file__)) + '/graph.html' @@ -48,21 +48,28 @@ with open(graph, "r") as html_chart_file: base_html_data = html_chart_file.read() + if "None" not in columns: + data_dict["None"] = [0] base_html_data = (base_html_data .replace("status", status) .replace("keywords", keywords) - .replace("var critical=[];", "var critical=[" + make_js_object_string(rcd.data_dict["critical"]) + "]") - .replace("var urgent=[];", "var urgent=[" + make_js_object_string(rcd.data_dict["urgent"]) + "]") - .replace("var bug=[];", "var bug=[" + make_js_object_string(rcd.data_dict["bug"]) + "]") - .replace("var feature=[];", "var feature=[" + make_js_object_string(rcd.data_dict["feature"]) + "]") - .replace("var wish=[];", "var wish=[" + make_js_object_string(rcd.data_dict["wish"]) + "]") - .replace("var noPrio=[];", "var noPrio=[" + make_js_object_string(rcd.data_dict["noPrio"]) + "]") - .replace("var timestamp=[];", "var timestamp=[" + make_js_object_date(rcd.data_dict["date"]) + "]")) + .replace("var critical=[];", "var critical=[" + make_js_object_string(data_dict["critical"]) + "]") + .replace("var urgent=[];", "var urgent=[" + make_js_object_string(data_dict["urgent"]) + "]") + .replace("var bug=[];", "var bug=[" + make_js_object_string(data_dict["bug"]) + "]") + .replace("var feature=[];", "var feature=[" + make_js_object_string(data_dict["feature"]) + "]") + .replace("var wish=[];", "var wish=[" + make_js_object_string(data_dict["wish"]) + "]") + .replace("var noPrio=[];", "var noPrio=[" + make_js_object_string(data_dict["None"]) + "]") + .replace("var timestamp=[];", "var timestamp=[" + make_js_object_date(data_dict["date"]) + "]")) return base_html_data -def compile_db_stats_html(db_file, sql_select, status="", keywords="", graph=None): +def compile_db_stats_html(db_file, sql_select, columns, status="", keywords="", graph=None): + + data_dict = {"date": []} + status_list = columns.split(", ") + for x in status_list: + data_dict[x] = [] con = None cur = None @@ -73,27 +80,24 @@ cur.execute(sql_select) for row in cur.fetchall(): - rcd.data_dict["date"].append(row[0]) - rcd.data_dict["critical"].append(row[1]) - rcd.data_dict["urgent"].append(row[2]) - rcd.data_dict["bug"].append(row[3]) - rcd.data_dict["feature"].append(row[4]) - rcd.data_dict["wish"].append(row[5]) - rcd.data_dict["noPrio"].append(row[6]) + data_dict["date"].append(row[0]) + for x in range(len(status_list)): + data_dict[status_list[x]].append(row[x+1]) + finally: if cur: cur.close() if con: con.close() - return get_webpage(status, keywords, graph) + return get_webpage(data_dict, columns, status, keywords, graph) def render_webpage(content): for line in content.split("\n"): print(line) -def render_db_stats_as_html(db_file, sql_select, status="", keywords=""): - render_webpage(compile_db_stats_html(db_file, sql_select, status, keywords)) +def render_db_stats_as_html(db_file, sql_select, columns, status="", keywords=""): + render_webpage(compile_db_stats_html(db_file, sql_select, columns, status, keywords)) if __name__ == '__main__': cgitb.enable()
--- a/display_issues_demo.py Tue Oct 23 13:06:16 2018 +0200 +++ b/display_issues_demo.py Fri Nov 02 17:06:45 2018 +0100 @@ -35,4 +35,4 @@ #render_db_stats_as_html("./demo1.db", rcd.SELECT_ALL) render_db_stats_as_html(db, rcd.build_sql_select(columns).format("timestamp > date('now', '-2 month')"), - status, keywords) + columns, status, keywords)