changeset 13:149d01f43e31

Split up render_db_stats_as_html function Allow the generated HTML code to be either printed to stdout as before (render_db_stats_as_html) or be returned as a string (compile_db_stats_html). The latter is required for Bottledash.
author Gernot Schulz <gernot@intevation.de>
date Sun, 31 Jan 2016 13:15:08 +0100
parents b9a2b828ad18
children b5f7a439bddd
files display_issues.py display_issues_demo.py
diffstat 2 files changed, 13 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/display_issues.py	Thu Dec 03 12:15:51 2015 +0100
+++ b/display_issues.py	Sun Jan 31 13:15:08 2016 +0100
@@ -20,6 +20,7 @@
 import sqlite3 as db
 import cgitb
 import roundup_content_data as rcd
+import os
 
 
 def make_js_object_string(array):
@@ -39,10 +40,11 @@
 
     return ", ".join(formated)
 
-
 def get_webpage():
 
-    with open("graph.html", "r") as html_chart_file:
+    graph = os.path.dirname(os.path.realpath(__file__)) + '/graph.html'
+
+    with open(graph, "r") as html_chart_file:
         base_html_data = html_chart_file.read()
 
     base_html_data = (base_html_data
@@ -55,13 +57,7 @@
 
     return base_html_data
 
-
-def render_webpage(content):
-    for line in content.split("\n"):
-        print(line)
-
-
-def render_db_stats_as_html(db_file, sql_select):
+def compile_db_stats_html(db_file, sql_select):
 
     con = None
     cur = None
@@ -84,8 +80,14 @@
         if con:
             con.close()
 
-    render_webpage(get_webpage())
+    return get_webpage()
 
+def render_webpage(content):
+    for line in content.split("\n"):
+        print(line)
+
+def render_db_stats_as_html(db_file, sql_select):
+    render_webpage(compile_db_stats_html(db_file, sql_select))
 
 if __name__ == '__main__':
     cgitb.enable()
--- a/display_issues_demo.py	Thu Dec 03 12:15:51 2015 +0100
+++ b/display_issues_demo.py	Sun Jan 31 13:15:08 2016 +0100
@@ -16,8 +16,6 @@
 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)
 render_db_stats_as_html(rcd.DATABASE_DEMO,
-            rcd.SELECT_WHERE.format("timestamp > date('now', '-2 month')"))
+        rcd.SELECT_WHERE.format("timestamp > date('now', '-2 month')"))
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)