Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finished Donations Assignment01 - AS #10

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
web: python main.py
web: gunicorn main:app
53 changes: 47 additions & 6 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,63 @@
import base64

from flask import Flask, render_template, request, redirect, url_for, session

from model import Donation
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():
donations = Donation.select()
return render_template('donations.jinja2', donations=donations)

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", 6738))
port = int(os.environ.get("PORT", 5000))
app.run(host='0.0.0.0', port=port)

18 changes: 10 additions & 8 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
click==6.7
Flask==0.12.3
itsdangerous==0.24
Jinja2==2.10
MarkupSafe==1.0
peewee==3.2.2
psycopg2-binary==2.8.4
Werkzeug==0.14.1
click==7.1.2
Flask==1.1.2
gunicorn==20.0.4
itsdangerous==1.1.0
Jinja2==2.11.2
MarkupSafe==1.1.1
peewee==3.13.3
psycopg2==2.8.6
psycopg2-binary==2.8.6
Werkzeug==1.0.1
13 changes: 13 additions & 0 deletions templates/all_donations.jinja2
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{% extends 'base.jinja2' %}

{% block subtitle %}All Donors and Donations:{% endblock subtitle %}

{% block content %}
<b><hr>
<hr></b><br>
<ul>
{% for donation in all_donations %}
<li>Donor Name: <b>{{ donation.donor.name }}</b> ---- Amount Given: $<b>{{ donation.value }}</b></li>
{% endfor %}
</ul><br>
{% endblock content %}
6 changes: 6 additions & 0 deletions templates/base.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
<title>Mailroom</title>
</head>
<body>
<nav>
<a id="donations" href="{{ url_for('all') }}">Donor Summary (Home)</a> :
<a id="create" href="{{ url_for('create') }}"> Add a Donation </a> :
<a id="lookup" href="{{ url_for('donor_lookup') }}"> Donor Inquiry </a> :
<a id="all_donations" href="{{ url_for('all_donations') }}"> All Donations Listed </a>
</nav>
<h1>Donations</h1>
<h2>{% block subtitle %} {% endblock subtitle %}</h2>
{% block content %} {% endblock content %}
Expand Down
19 changes: 19 additions & 0 deletions templates/create.jinja2
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{% extends 'base.jinja2' %}

{% block subtitle %}Add a Donation Here:{% endblock subtitle %}

{% block content %}
<ul>
{% for donor in donors %}
<li><b>
{{ donor.name }}:</b>
<form method="POST">
<label for="number">Amount To Donate: $ </label>
<input type="number" id="number" name="number">
<input type="hidden" name="donor" value="{{ donor }}">
<input type="submit" value="Add New Donation?">
</form>
</li>
{% endfor %}
</ul>
{% endblock content %}
10 changes: 6 additions & 4 deletions templates/donations.jinja2
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
{% extends 'base.jinja2' %}

{% block subtitle %}Donations{% endblock subtitle %}
{% block subtitle %}Total Donations By Donor To Date:{% endblock subtitle %}

{% block content %}
<hr>
<ul>
{% for donation in donations %}
<li><b>{{ donation.donor.name }}</b>: {{ donation.value }}</li>
{% endfor %}
</ul>
<li>Donor Name: <b>{{ donation.get("Name") }}</b> ---- Amount Given: $<b>{{ donation.get("Amount") }}</b><br></li>
<br>
{% endfor %} <br>
</ul><br>
{% endblock content %}
18 changes: 18 additions & 0 deletions templates/lookup.jinja2
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{% extends 'base.jinja2' %}

{% block subtitle %}Donor Inquiry: {% endblock subtitle %}

{% block content %}
<hr><br>
<form method="GET">
<label for="name">Donor Name: </label><input type="text" id="name" name="name">
<input type="submit" value="look It Up!!">
</form>
<form method="POST">
<ul>
{% for donation in all_donations %}
<li>Donor Name: <b>{{ donation.donor.name }}</b> ---- Amount Given: $<b>{{ donation.value }}</b></li>
{% endfor %}
</ul><br>
</form>
{% endblock content %}