New Membership Page and other changes #4

Merged
kumi merged 29 commits from membership-page into main 2024-05-30 10:15:10 +00:00
5 changed files with 44 additions and 17 deletions
Showing only changes of commit 2a174aa342 - Show all commits

View file

@ -1,6 +1,14 @@
from decimal import Decimal 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): def get_transparency_data(data, year=None, month=None):
if year is None: if year is None:
year = max(data.keys()) year = max(data.keys())

44
main.py
View file

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

View file

@ -78,14 +78,13 @@
<div class="card shadow-sm mt-4"> <div class="card shadow-sm mt-4">
<div class="card-body"> <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"> <p class="card-text">
We believe in transparency and accountability. Below is a summary of our 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> </p>
<div class="table-responsive"> <div class="table-responsive">{{ finances|safe }}</div>
{{ finances|safe }}
</div>
</div> </div>
</div> </div>