Mercurial > roundup-cc
view display_issues.py @ 17:adca5b3780d2
Add collecting no-prio issues. Restructure.
* Move usage examples from collect_issues.py to examples/.
Also add a section about this to the readme. This should
make it easier to understand how it all works together.
As we have two examples now, hardcode the database filenames.
* Add a function to create the necessary database command from a list
of columns. This makes it easier to work with tracker that have
customized their priorities,
* Add an example how to collect no-prio issues in a database.
Note that the display part is not included.
* Cleanup roundup_content_data by removing db file name suggestions
and unused "reference db" command. This could be re-added for specific
installations if they need it, however it probably should be separated
as configuration.
author | Bernhard Reiter <bernhard@intevation.de> |
---|---|
date | Mon, 09 Jul 2018 12:28:28 +0200 |
parents | b5f7a439bddd |
children | 3bb3d9a9f1b7 |
line wrap: on
line source
#!/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 ##Usage Example: ## see display_issues_demo.py or __main__ section below. """ import sqlite3 as db import cgitb import roundup_content_data as rcd import os 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(graph=None): if graph is None: 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 .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 compile_db_stats_html(db_file, sql_select, graph=None): con = None cur = None try: con = db.connect(db_file) cur = con.cursor() cur.execute(sql_select) 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() return get_webpage(graph) 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() #spit out HTML file directly, thus no need to give headers to the server #print("Content-Type: text/html") #print() render_db_stats_as_html("./demo1.db", rcd.SELECT_ALL)