New Membership Page and other changes #4
5 changed files with 44 additions and 17 deletions
|
@ -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
44
main.py
|
@ -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
|
||||
|
||||
|
|
|
@ -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>
|
||||
|
||||
|
|
Loading…
Reference in a new issue