Mercurial > roundup-cc
comparison display_issues.py @ 13:149d01f43e31
Split up render_db_stats_as_html function
Allow the generated HTML code to be either printed to stdout as before
(render_db_stats_as_html) or be returned as a string (compile_db_stats_html).
The latter is required for Bottledash.
author | Gernot Schulz <gernot@intevation.de> |
---|---|
date | Sun, 31 Jan 2016 13:15:08 +0100 |
parents | 99e2e0e17103 |
children | b5f7a439bddd |
comparison
equal
deleted
inserted
replaced
12:b9a2b828ad18 | 13:149d01f43e31 |
---|---|
18 """ | 18 """ |
19 | 19 |
20 import sqlite3 as db | 20 import sqlite3 as db |
21 import cgitb | 21 import cgitb |
22 import roundup_content_data as rcd | 22 import roundup_content_data as rcd |
23 import os | |
23 | 24 |
24 | 25 |
25 def make_js_object_string(array): | 26 def make_js_object_string(array): |
26 formated = [] | 27 formated = [] |
27 | 28 |
37 for item in array: | 38 for item in array: |
38 formated.append("{date : new Date('" + str(item) + "')}") | 39 formated.append("{date : new Date('" + str(item) + "')}") |
39 | 40 |
40 return ", ".join(formated) | 41 return ", ".join(formated) |
41 | 42 |
42 | |
43 def get_webpage(): | 43 def get_webpage(): |
44 | 44 |
45 with open("graph.html", "r") as html_chart_file: | 45 graph = os.path.dirname(os.path.realpath(__file__)) + '/graph.html' |
46 | |
47 with open(graph, "r") as html_chart_file: | |
46 base_html_data = html_chart_file.read() | 48 base_html_data = html_chart_file.read() |
47 | 49 |
48 base_html_data = (base_html_data | 50 base_html_data = (base_html_data |
49 .replace("var critical=[];", "var critical=[" + make_js_object_string(rcd.data_dict["critical"]) + "]") | 51 .replace("var critical=[];", "var critical=[" + make_js_object_string(rcd.data_dict["critical"]) + "]") |
50 .replace("var urgent=[];", "var urgent=[" + make_js_object_string(rcd.data_dict["urgent"]) + "]") | 52 .replace("var urgent=[];", "var urgent=[" + make_js_object_string(rcd.data_dict["urgent"]) + "]") |
53 .replace("var wish=[];", "var wish=[" + make_js_object_string(rcd.data_dict["wish"]) + "]") | 55 .replace("var wish=[];", "var wish=[" + make_js_object_string(rcd.data_dict["wish"]) + "]") |
54 .replace("var timestamp=[];", "var timestamp=[" + make_js_object_date(rcd.data_dict["date"]) + "]")) | 56 .replace("var timestamp=[];", "var timestamp=[" + make_js_object_date(rcd.data_dict["date"]) + "]")) |
55 | 57 |
56 return base_html_data | 58 return base_html_data |
57 | 59 |
58 | 60 def compile_db_stats_html(db_file, sql_select): |
59 def render_webpage(content): | |
60 for line in content.split("\n"): | |
61 print(line) | |
62 | |
63 | |
64 def render_db_stats_as_html(db_file, sql_select): | |
65 | 61 |
66 con = None | 62 con = None |
67 cur = None | 63 cur = None |
68 | 64 |
69 try: | 65 try: |
82 if cur: | 78 if cur: |
83 cur.close() | 79 cur.close() |
84 if con: | 80 if con: |
85 con.close() | 81 con.close() |
86 | 82 |
87 render_webpage(get_webpage()) | 83 return get_webpage() |
88 | 84 |
85 def render_webpage(content): | |
86 for line in content.split("\n"): | |
87 print(line) | |
88 | |
89 def render_db_stats_as_html(db_file, sql_select): | |
90 render_webpage(compile_db_stats_html(db_file, sql_select)) | |
89 | 91 |
90 if __name__ == '__main__': | 92 if __name__ == '__main__': |
91 cgitb.enable() | 93 cgitb.enable() |
92 #spit out HTML file directly, thus no need to give headers to the server | 94 #spit out HTML file directly, thus no need to give headers to the server |
93 #print("Content-Type: text/html") | 95 #print("Content-Type: text/html") |