changeset 3:99c68ebfb3b9

Streamlined to example use. * removed superfluous file * added example file for usage as python module
author Bernhard Reiter <bernhard@intevation.de>
date Mon, 30 Nov 2015 17:46:22 +0100
parents 3e9f4a6803d1
children 0b65eb9ecb79
files display_issues display_issues.py display_issues_demo.py
diffstat 3 files changed, 31 insertions(+), 94 deletions(-) [+]
line wrap: on
line diff
--- a/display_issues	Wed Apr 15 11:40:28 2015 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,91 +0,0 @@
-#!/usr/bin/env python3
-
-""" Display previously saved issues from a database on webpage via CGI.
-
-author: Sascha L. Teichmann <sascha.teichmann@intevation.de>
-author: Bernhard Reiter <bernhard@intevation.de>
-author: Sean Engelhardt <sean.engelhardt@intevation.de>
-
-(c) 2010,2015 by Intevation GmbH
-
-This is Free Software unter the terms of the
-GNU GENERAL PUBLIC LICENSE Version 3 or later.
-See http://www.gnu.org/licenses/gpl-3.0.txt for details
-"""
-
-import sqlite3 as db
-import cgitb
-import roundup_content_data as rcd
-
-
-def make_js_object_string(array):
-    formated = []
-
-    for item in array:
-        formated.append("{points: " + str(item) + "}")
-
-    return ",".join(formated)
-
-
-def make_js_object_date(array):
-    formated = []
-
-    for item in array:
-        formated.append("{date : new Date('" + str(item) + "')}")
-
-    return ", ".join(formated)
-
-
-def get_webpage():
-
-    with open ("graph.html", "r") as html_chart_file:
-        base_html_data = html_chart_file.read()
-
-    base_html_data = (base_html_data
-        .replace("var critical=[];", "var critical=[" + make_js_object_string(rcd.data_dict["critical"]) + "]")
-        .replace("var urgent=[];", "var urgent=[" + make_js_object_string(rcd.data_dict["urgent"]) + "]")
-        .replace("var bug=[];", "var bug=[" + make_js_object_string(rcd.data_dict["bug"]) + "]")
-        .replace("var feature=[];", "var feature=[" + make_js_object_string(rcd.data_dict["feature"]) + "]")
-        .replace("var wish=[];", "var wish=[" + make_js_object_string(rcd.data_dict["wish"]) + "]")
-        .replace("var timestamp=[];", "var timestamp=[" + make_js_object_date(rcd.data_dict["date"]) + "]"))
-
-    return base_html_data
-
-
-def render_webpage(content):
-    for line in content.split("\n"):
-        print(line)
-
-
-def render_db_stats_as_html():
-
-    con = None
-    cur = None
-
-    try:
-        con = db.connect(rcd.DATABASE_FILE)
-        cur = con.cursor()
-        cur.execute(rcd.SELECT_ALL)
-
-        for row in cur.fetchall():
-            rcd.data_dict["date"].append(row[0])
-            rcd.data_dict["critical"].append(row[1])
-            rcd.data_dict["urgent"].append(row[2])
-            rcd.data_dict["bug"].append(row[3])
-            rcd.data_dict["feature"].append(row[4])
-            rcd.data_dict["wish"].append(row[5])
-    finally:
-        if cur:
-            cur.close()
-        if con:
-            con.close()
-
-    render_webpage(get_webpage())
-
-
-cgitb.enable()
-print("Content-Type: text/html")
-print()
-
-
-render_db_stats_as_html()
--- a/display_issues.py	Wed Apr 15 11:40:28 2015 +0200
+++ b/display_issues.py	Mon Nov 30 17:46:22 2015 +0100
@@ -15,6 +15,10 @@
 
 ##Usage Example: ##
 
+from display_issues import *
+cgitb.enable() # (optional) HTML traceback to browser
+print("Content-Type: text/html")
+print()
 render_db_stats_as_html(rcd.DATABASE_DEMO, rcd.SELECT_ALL)
 """
 
@@ -88,6 +92,9 @@
     render_webpage(get_webpage())
 
 
-cgitb.enable()
-print("Content-Type: text/html")
-print()
\ No newline at end of file
+if __name__ == '__main__':
+    cgitb.enable()
+    print("Content-Type: text/html")
+    print()
+
+    render_db_stats_as_html(rcd.DATABASE_DEMO, rcd.SELECT_ALL)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/display_issues_demo.py	Mon Nov 30 17:46:22 2015 +0100
@@ -0,0 +1,21 @@
+#!/usr/bin/env python3
+
+""" Fetch issues from a roundup-tracker and save them in a databse.
+
+author: Sascha L. Teichmann <sascha.teichmann@intevation.de>
+author: Bernhard Reiter <bernhard@intevation.de>
+author: Sean Engelhardt <sean.engelhardt@intevation.de>
+
+(c) 2010,2015 by Intevation GmbH
+
+This is Free Software unter the terms of the
+GNU GENERAL PUBLIC LICENSE Version 3 or later.
+See http://www.gnu.org/licenses/gpl-3.0.txt for details
+"""
+
+from display_issues import *
+
+cgitb.enable() # (optional) HTML traceback to browser
+print("Content-Type: text/html")
+print()
+render_db_stats_as_html(rcd.DATABASE_DEMO, rcd.SELECT_ALL)
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)