forked from pcewebpython/flask-mailroom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
46 lines (34 loc) · 1.2 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
import os
import base64
import random
from flask import Flask, render_template, request, redirect, url_for, session
from model import db, Donor, Donation
app = Flask(__name__)
@app.route('/')
def home():
return redirect(url_for('all'))
@app.route('/donations/')
def all():
donations = Donation.select()
return render_template('donations.jinja2', donations=donations)
@app.route('/create', methods=['GET', 'POST'])
def create():
if request.method == 'POST':
name_input = request.form['name']
value_input = request.form['value']
name_exists = False
for donor in Donor.select():
if donor.name == name_input:
Donation(donor=donor, value=int(value_input)).save()
name_exists = True
if not name_exists:
new_donor = Donor(name=name_input)
new_donor.save()
new_donation = Donation(donor=new_donor, value=int(value_input))
new_donation.save()
return redirect(url_for('all'))
else:
return render_template('create.jinja2')
if __name__ == "__main__":
port = int(os.environ.get("PORT", 6738))
app.run(host='0.0.0.0', port=port)