annotate modules/roundup_cc/display_issues.py @ 11:7a573ec679a6

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