Mercurial > roundup-cc
comparison display_issues @ 0:3f139db894f1
initial commit
author | sean |
---|---|
date | Thu, 02 Apr 2015 09:51:19 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:3f139db894f1 |
---|---|
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 import sqlite3 as db | |
17 import cgitb | |
18 import roundup_content_data as rcd | |
19 | |
20 | |
21 def make_js_object_string(array): | |
22 formated = [] | |
23 | |
24 for item in array: | |
25 formated.append("{points: " + str(item) + "}") | |
26 | |
27 return ",".join(formated) | |
28 | |
29 | |
30 def make_js_object_date(array): | |
31 formated = [] | |
32 | |
33 for item in array: | |
34 formated.append("{date : new Date('" + str(item) + "')}") | |
35 | |
36 return ", ".join(formated) | |
37 | |
38 | |
39 def get_webpage(): | |
40 | |
41 with open ("graph.html", "r") as html_chart_file: | |
42 base_html_data = html_chart_file.read() | |
43 | |
44 base_html_data = (base_html_data | |
45 .replace("var critical=[];", "var critical=[" + make_js_object_string(rcd.data_dict["critical"]) + "]") | |
46 .replace("var urgent=[];", "var urgent=[" + make_js_object_string(rcd.data_dict["urgent"]) + "]") | |
47 .replace("var bug=[];", "var bug=[" + make_js_object_string(rcd.data_dict["bug"]) + "]") | |
48 .replace("var feature=[];", "var feature=[" + make_js_object_string(rcd.data_dict["feature"]) + "]") | |
49 .replace("var wish=[];", "var wish=[" + make_js_object_string(rcd.data_dict["wish"]) + "]") | |
50 .replace("var timestamp=[];", "var timestamp=[" + make_js_object_date(rcd.data_dict["date"]) + "]")) | |
51 | |
52 return base_html_data | |
53 | |
54 | |
55 def render_webpage(content): | |
56 for line in content.split("\n"): | |
57 print(line) | |
58 | |
59 | |
60 def render_db_stats_as_html(): | |
61 | |
62 con = None | |
63 cur = None | |
64 | |
65 try: | |
66 con = db.connect(rcd.DATABASE_FILE) | |
67 cur = con.cursor() | |
68 cur.execute(rcd.SELECT_ALL) | |
69 | |
70 for row in cur.fetchall(): | |
71 rcd.data_dict["date"].append(row[0]) | |
72 rcd.data_dict["critical"].append(row[1]) | |
73 rcd.data_dict["urgent"].append(row[2]) | |
74 rcd.data_dict["bug"].append(row[3]) | |
75 rcd.data_dict["feature"].append(row[4]) | |
76 rcd.data_dict["wish"].append(row[5]) | |
77 finally: | |
78 if cur: | |
79 cur.close() | |
80 if con: | |
81 con.close() | |
82 | |
83 render_webpage(get_webpage()) | |
84 | |
85 | |
86 cgitb.enable() | |
87 print("Content-Type: text/html") | |
88 print() | |
89 | |
90 | |
91 render_db_stats_as_html() |