From f423750248f84161aab945f2a45d69333ab5e03e Mon Sep 17 00:00:00 2001 From: fram3d Date: Thu, 13 Jul 2023 20:01:57 +0200 Subject: [PATCH] add progress bar to subscribe.html --- donationcalc/models.py | 11 ++++++++++- donationcalc/routes.py | 15 +++++++++------ donationcalc/templates/subscribe.html | 5 +++++ 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/donationcalc/models.py b/donationcalc/models.py index 1932024..11be5c2 100644 --- a/donationcalc/models.py +++ b/donationcalc/models.py @@ -71,7 +71,16 @@ class sender(): sendmail(donor, "Not enough funds", "Not enough funds for next month.") return 0 - + + def pledged(self): + sum = 0 + f = open("donors.txt", "r") + + for line in f: + sum += int(line.split(",")[1]) + + return sum + class donor(): ''' Class that represents a donor diff --git a/donationcalc/routes.py b/donationcalc/routes.py index d0a909e..38a4954 100644 --- a/donationcalc/routes.py +++ b/donationcalc/routes.py @@ -5,13 +5,16 @@ import donationcalc.donationconfig @app.route('/donations/subscribe/', methods=['POST', 'GET']) def subscribe(): - if request.method == 'GET': - return render_template('subscribe.html') - elif request.method == 'POST': - config = donationcalc.donationconfig.donationconfig() - currency = config.currency - sender = donationcalc.models.sender() + config = donationcalc.donationconfig.donationconfig() + currency = config.currency + sender = donationcalc.models.sender() + currentlypledged = sender.pledged() + currentpercent = round(currentlypledged/int(config.monthlycost), 2) + + if request.method == 'GET': + return render_template('subscribe.html', monthlycost = int(config.monthlycost), pledged = currentlypledged, percent = currentpercent) + elif request.method == 'POST': donoremail = request.form['email'] donormonthly = request.form['monthly'] diff --git a/donationcalc/templates/subscribe.html b/donationcalc/templates/subscribe.html index 81d08fe..efa902e 100644 --- a/donationcalc/templates/subscribe.html +++ b/donationcalc/templates/subscribe.html @@ -10,6 +10,8 @@ margin: 0 auto; font-family: Arial, Helvetica, sans-serif; color: #3d3d3d; + display: flex; + flex-direction: column; } body { @@ -19,6 +21,9 @@
+

Currently pledged to donate

+ {{ percent }}% +

Subscribe for donation notifications