Implemented dynamic financial transparency tables to automatically generate and display monthly financial data for memberships, including incomes, expenses, and balances across multiple currencies. This change involved adding a new `finances.py` helper to process financial data and integrate it with the existing Flask application. Additionally, adjusted the CSS for better alignment and readability of currency columns in the transparency tables. - Introduced a `generate_transparency_table` function to generate HTML tables dynamically based on the latest financial data. - Expanded the `main.py` Flask route for the membership page to include financial data rendering, ensuring up-to-date information is presented to users. - Removed static HTML table from the membership template in favor of dynamically generated content, offering real-time insight into finances. - Adjusted the width and text alignment of currency columns in `base.css` for enhanced table aesthetics and readability. This update significantly improves the transparency of financial information, making it easier for members to understand the flow of funds within the organization.
74 lines
1.8 KiB
Python
74 lines
1.8 KiB
Python
from flask import Flask, render_template, send_from_directory
|
|
from jinja2 import TemplateNotFound
|
|
|
|
import json
|
|
import pathlib
|
|
import os
|
|
|
|
from argparse import ArgumentParser
|
|
|
|
from helpers.finances import generate_transparency_table, get_transparency_data
|
|
|
|
app = Flask(__name__)
|
|
|
|
|
|
@app.route("/assets/<path:path>")
|
|
def send_assets(path):
|
|
return send_from_directory("assets", path)
|
|
|
|
|
|
@app.route("/", defaults={"path": "index"})
|
|
@app.route("/<path:path>.html")
|
|
def catch_all(path):
|
|
try:
|
|
services = json.loads(
|
|
(pathlib.Path(__file__).parent / "services.json").read_text()
|
|
)
|
|
|
|
warning = None
|
|
|
|
if app.development_mode:
|
|
warning = render_template("prod-warning.html")
|
|
|
|
kwargs = {
|
|
"services": services,
|
|
"warning": warning,
|
|
}
|
|
|
|
if path == "membership":
|
|
finances = json.loads(
|
|
(pathlib.Path(__file__).parent / "finances.json").read_text()
|
|
)
|
|
|
|
finances_table = generate_transparency_table(
|
|
get_transparency_data(finances)
|
|
)
|
|
|
|
kwargs.update(
|
|
{
|
|
"finances": finances_table,
|
|
}
|
|
)
|
|
|
|
return render_template(f"{path}.html", **kwargs)
|
|
except TemplateNotFound:
|
|
return "404 Not Found", 404
|
|
|
|
|
|
app.development_mode = False
|
|
|
|
if os.environ.get("PRIVATECOFFEE_DEV"):
|
|
app.development_mode = True
|
|
|
|
|
|
if __name__ == "__main__":
|
|
parser = ArgumentParser(description="Run the private.coffee web server.")
|
|
parser.add_argument("--port", type=int, default=9810)
|
|
parser.add_argument("--debug", action="store_true")
|
|
parser.add_argument("--dev", action="store_true")
|
|
args = parser.parse_args()
|
|
|
|
app.development_mode = args.dev or app.development_mode
|
|
|
|
app.run(port=args.port, debug=args.debug)
|