comparison display_issues.py @ 1:2df45f6ecd81

new appereance (solid and dotted lines), resonsive layout, new legend, new structure, cronjob-friendly dynamic generation of search-strings, dynamic recognition of error-values, ignores non-numeric priority-IDs
author sean
date Tue, 14 Apr 2015 13:32:12 +0200
parents
children 3e9f4a6803d1
comparison
equal deleted inserted replaced
0:3f139db894f1 1:2df45f6ecd81
1 #!/usr/bin/env python3
2
3 """ Display previously saved issues from a database on webpage via CGI.
4
5 author: Sascha L. Teichmann <sascha.teichmann@intevation.de>
6 author: Bernhard Reiter <bernhard@intevation.de>
7 author: Sean Engelhardt <sean.engelhardt@intevation.de>
8
9 (c) 2010,2015 by Intevation GmbH
10
11 This is Free Software unter the terms of the
12 GNU GENERAL PUBLIC LICENSE Version 3 or later.
13 See http://www.gnu.org/licenses/gpl-3.0.txt for details
14
15
16 ##Usage Example: ##
17
18 render_db_stats_as_html(rcd.DATABASE_DEMO, rcd.SELECT_ALL)
19
20 """
21
22 import sqlite3 as db
23 import cgitb
24 import roundup_content_data as rcd
25
26
27 def make_js_object_string(array):
28 formated = []
29
30 for item in array:
31 formated.append("{points: " + str(item) + "}")
32
33 return ",".join(formated)
34
35
36 def make_js_object_date(array):
37 formated = []
38
39 for item in array:
40 formated.append("{date : new Date('" + str(item) + "')}")
41
42 return ", ".join(formated)
43
44
45 def get_webpage():
46
47 with open("graph.html", "r") as html_chart_file:
48 base_html_data = html_chart_file.read()
49
50 base_html_data = (base_html_data
51 .replace("var critical=[];", "var critical=[" + make_js_object_string(rcd.data_dict["critical"]) + "]")
52 .replace("var urgent=[];", "var urgent=[" + make_js_object_string(rcd.data_dict["urgent"]) + "]")
53 .replace("var bug=[];", "var bug=[" + make_js_object_string(rcd.data_dict["bug"]) + "]")
54 .replace("var feature=[];", "var feature=[" + make_js_object_string(rcd.data_dict["feature"]) + "]")
55 .replace("var wish=[];", "var wish=[" + make_js_object_string(rcd.data_dict["wish"]) + "]")
56 .replace("var timestamp=[];", "var timestamp=[" + make_js_object_date(rcd.data_dict["date"]) + "]"))
57
58 return base_html_data
59
60
61 def render_webpage(content):
62 for line in content.split("\n"):
63 print(line)
64
65
66 def render_db_stats_as_html(db_file, sql_select):
67
68 con = None
69 cur = None
70
71 try:
72 con = db.connect(db_file)
73 cur = con.cursor()
74 cur.execute(sql_select)
75
76 for row in cur.fetchall():
77 rcd.data_dict["date"].append(row[0])
78 rcd.data_dict["critical"].append(row[1])
79 rcd.data_dict["urgent"].append(row[2])
80 rcd.data_dict["bug"].append(row[3])
81 rcd.data_dict["feature"].append(row[4])
82 rcd.data_dict["wish"].append(row[5])
83 finally:
84 if cur:
85 cur.close()
86 if con:
87 con.close()
88
89 render_webpage(get_webpage())
90
91
92 cgitb.enable()
93 print("Content-Type: text/html")
94 print()
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)