annotate modules/web_view/display_issues.py @ 23:f63737665ac5

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