-
Notifications
You must be signed in to change notification settings - Fork 147
/
Copy pathmain.py
64 lines (52 loc) · 2.27 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import os
import base64
from flask import Flask, render_template, request, redirect, url_for, session
from model import Donation, Donor
app = Flask(__name__)
#app.secret_key = b'/\x17\x1c\xef\xd0\x80\xfd\xb0j\xf2\x88\xbdZ\r\xb8^\x9b\n1E\xf3@\xd4\xb3'
app.secret_key = os.environ.get('SECRET_KEY').encode()
@app.route('/')
def home():
return redirect(url_for('all'))
@app.route('/create', methods=['GET', 'POST'])
def create():
if request.method == 'POST':
Donation.insert(donor=request.form['donor'], value=request.form['number']).execute()
return redirect(url_for('all'))
else:
return render_template('create.jinja2', donors=Donor.select().distinct())
@app.route('/donations/')
def all():
Tot_Donor_List = []
donors = Donor.select()
for donor in donors:
donations = Donation.select().where(Donation.donor == donor)
don_tot = 0
for donation in donations:
don_tot += int(donation.value)
Tot_Donor_List.append({"Name": donor.name, "Amount": '{:,.2f}'.format(don_tot)})
return render_template('donations.jinja2', donations=Tot_Donor_List)
@app.route('/all_donations')
def all_donations():
all_donations = Donation.select().where(Donation.donor).order_by(Donation.donor, Donation.value)
return render_template('all_donations.jinja2', all_donations=all_donations)
@app.route('/lookup', methods=['GET', 'POST'])
def donor_lookup():
# I need some help with this
# if request.method == 'GET':
# donor_name = request.form['name']
# try:
# print("Made it here try")
# Test_attr = Donation.select().where(Donation.donor.name == donor_name)
# print("try the Test!")
# if request.form['name'] in Test_attr :
# print("Made it here2")
# all_donations = Donation.select().where(Donation.donor==request.form['name']).order_by(Donation.value)
# return render_template('lookup.jinja2', all_donations=all_donations)
# raise ValueError
# except ValueError:
# return render_template('lookup.jinja2', error="Name not found.")
return render_template('lookup.jinja2')
if __name__ == "__main__":
port = int(os.environ.get("PORT", 5000))
app.run(host='0.0.0.0', port=port)