annotate display_issues @ 0:3f139db894f1

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