Mercurial > bottledash
comparison modules/web_view/display_issues.py @ 16:f89ad628f831
adding the renamed files
author | sean |
---|---|
date | Wed, 05 Aug 2015 13:33:15 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
15:82d66f4488cd | 16:f89ad628f831 |
---|---|
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 import sqlite3 as db | |
22 import cgitb, os, sys, inspect | |
23 import web_view.roundup_content_data as rcd | |
24 | |
25 PATH = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) | |
26 HTML_DATA = "graph.html" | |
27 PATH_TO_HTML = PATH + "/" + HTML_DATA | |
28 | |
29 def make_js_object_string(array): | |
30 formated = [] | |
31 | |
32 for item in array: | |
33 formated.append("{points: " + str(item) + "}") | |
34 | |
35 return ",".join(formated) | |
36 | |
37 | |
38 def make_js_object_date(array): | |
39 formated = [] | |
40 | |
41 for item in array: | |
42 formated.append("{date : new Date('" + str(item) + "')}") | |
43 | |
44 return ", ".join(formated) | |
45 | |
46 | |
47 def get_webpage(): | |
48 | |
49 with open(PATH_TO_HTML, "r") as html_chart_file: | |
50 base_html_data = html_chart_file.read() | |
51 | |
52 base_html_data = (base_html_data | |
53 .replace("var critical=[];", "var critical=[" + make_js_object_string(rcd.data_dict["critical"]) + "]") | |
54 .replace("var urgent=[];", "var urgent=[" + make_js_object_string(rcd.data_dict["urgent"]) + "]") | |
55 .replace("var bug=[];", "var bug=[" + make_js_object_string(rcd.data_dict["bug"]) + "]") | |
56 .replace("var feature=[];", "var feature=[" + make_js_object_string(rcd.data_dict["feature"]) + "]") | |
57 .replace("var wish=[];", "var wish=[" + make_js_object_string(rcd.data_dict["wish"]) + "]") | |
58 .replace("var timestamp=[];", "var timestamp=[" + make_js_object_date(rcd.data_dict["date"]) + "]")) | |
59 | |
60 return base_html_data | |
61 | |
62 | |
63 # def render_webpage(content): | |
64 # webpage_string = "" | |
65 # for line in content.split("\n"): | |
66 # print(line) | |
67 | |
68 | |
69 def render_db_stats_as_html(db_file, sql_select): | |
70 | |
71 con = None | |
72 cur = None | |
73 | |
74 try: | |
75 con = db.connect(db_file) | |
76 cur = con.cursor() | |
77 cur.execute(sql_select) | |
78 | |
79 for row in cur.fetchall(): | |
80 rcd.data_dict["date"].append(row[0]) | |
81 rcd.data_dict["critical"].append(row[1]) | |
82 rcd.data_dict["urgent"].append(row[2]) | |
83 rcd.data_dict["bug"].append(row[3]) | |
84 rcd.data_dict["feature"].append(row[4]) | |
85 rcd.data_dict["wish"].append(row[5]) | |
86 finally: | |
87 if cur: | |
88 cur.close() | |
89 if con: | |
90 con.close() | |
91 | |
92 # render_webpage(get_webpage()) | |
93 # print(get_webpage()) | |
94 return get_webpage() | |
95 | |
96 # cgitb.enable() | |
97 # print("Content-Type: text/html") | |
98 # print() |