feat: Enhance data structure and transparency features

- Moved `finances.json` and `services.json` to a new `data` directory for better organization.
- Introduced `get_latest_month` function in `helpers/finances.py` to dynamically determine the latest financial reporting period.
- Updated `main.py` to use the new data paths and implement dynamic generation of the transparency report date, improving the clarity of financial reports.
- Modified `membership.html` template to display financial report for the dynamically determined latest month, enhancing transparency for donations.

These changes aim to improve data management, make financial reporting more transparent, and ensure users have access to the most current financial information. Moving JSON files to a dedicated directory helps with organizing resources better. By dynamically determining the latest financial period, the application now avoids hard-coded dates, increasing accuracy and reducing maintenance effort.
This commit is contained in:
Kumi 2024-05-29 15:04:57 +02:00
parent 6033a47b6a
commit 2a174aa342
Signed by: kumi
GPG key ID: ECBCC9082395383F
5 changed files with 44 additions and 17 deletions

View file

@ -1,6 +1,14 @@
from decimal import Decimal
def get_latest_month(data):
years = sorted(data.keys())
latest_year = years[-1]
months = sorted(data[latest_year].keys())
latest_month = months[-1]
return int(latest_month), int(latest_year)
def get_transparency_data(data, year=None, month=None):
if year is None:
year = max(data.keys())

44
main.py
View file

@ -4,10 +4,15 @@ from jinja2 import TemplateNotFound
import json
import pathlib
import os
import datetime
from argparse import ArgumentParser
from helpers.finances import generate_transparency_table, get_transparency_data
from helpers.finances import (
generate_transparency_table,
get_transparency_data,
get_latest_month,
)
app = Flask(__name__)
@ -21,25 +26,38 @@ def send_assets(path):
@app.route("/<path:path>.html")
def catch_all(path):
try:
services = json.loads(
(pathlib.Path(__file__).parent / "services.json").read_text()
)
warning = None
kwargs = {}
if app.development_mode:
warning = render_template("prod-warning.html")
kwargs.update(
{
"warning": render_template("prod-warning.html"),
}
)
kwargs = {
"services": services,
"warning": warning,
}
if path in (
"index",
"simple",
):
services = json.loads(
(pathlib.Path(__file__).parent / "data" / "services.json").read_text()
)
kwargs.update(
{
"services": services,
}
)
if path == "membership":
finances = json.loads(
(pathlib.Path(__file__).parent / "finances.json").read_text()
(pathlib.Path(__file__).parent / "data" / "finances.json").read_text()
)
finances_month, finances_year = get_latest_month(finances)
finances_period = datetime.date(finances_year, finances_month, 1)
finances_period_str = finances_period.strftime("%B %Y")
finances_table = generate_transparency_table(
get_transparency_data(finances)
)
@ -47,10 +65,12 @@ def catch_all(path):
kwargs.update(
{
"finances": finances_table,
"finances_period": finances_period_str,
}
)
return render_template(f"{path}.html", **kwargs)
except TemplateNotFound:
return "404 Not Found", 404

View file

@ -78,14 +78,13 @@
<div class="card shadow-sm mt-4">
<div class="card-body">
<h5 class="card-title">Transparency Report for May 2024</h5>
<h5 class="card-title">Transparency Report for {{ finances_period }}</h5>
<p class="card-text">
We believe in transparency and accountability. Below is a summary of our
income and expenses for the last month.
income and expenses for the last month, so you can see how your
donations are being used.
</p>
<div class="table-responsive">
{{ finances|safe }}
</div>
<div class="table-responsive">{{ finances|safe }}</div>
</div>
</div>