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

Adding the new donations option #4

Open
wants to merge 1 commit 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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Flask Mailroom Application

Running at [http://afternoon-reef-51666.herokuapp.com/donations/](http://afternoon-reef-51666.herokuapp.com/donations/).
Running at [http://stormy-hollows-70309.herokuapp.com/donations/](http://stormy-hollows-70309.herokuapp.com/donations/).
http://stormy-hollows-70309.herokuapp.com/add

## Your Task

Expand Down
29 changes: 28 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

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

from model import Donation
from model import Donation, Donor

app = Flask(__name__)

Expand All @@ -16,6 +16,33 @@ def all():
donations = Donation.select()
return render_template('donations.jinja2', donations=donations)

@app.route('/add', methods=['GET', 'POST'])
def add():

if request.method == 'POST':
# Handle the form submission
# f_name = request.form['name']
# amount = request.form['amount']
query = Donor.select().where(Donor.name == request.form['name'])
if query.exists():
Donation(donor=request.form['name'], value=request.form['amount']).save()
else:
f_name = Donor(name=request.form['name'])
f_name.save()
Donation(donor=f_name, value=request.form['amount']).save()



# if f_name == d_name:
# # existing_donation = Donation.select().where(Donor.name == request.form['name']).get()
# # updated_donation = existing_donation.value + int(amount)
# # Donation.update(value=updated_donation).where(Donor.name == request.form['name']).execute()
# Donor.create(name=f_name)
# Donation.
return redirect(url_for('all'))

else:
return render_template('new_donations.jinja2')

if __name__ == "__main__":
port = int(os.environ.get("PORT", 6738))
Expand Down
2 changes: 1 addition & 1 deletion model.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Meta:

class Donation(Model):
value = IntegerField()
donor = ForeignKeyField(Donor, backref='donations')
donor = ForeignKeyField(model=Donor, backref='donations')

class Meta:
database = db
Expand Down
15 changes: 15 additions & 0 deletions templates/new_donations.jinja2
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{% extends 'base.jinja2' %}

{% block subtitle %}New Donations {% endblock subtitle %}

{% block content %}
{# <p>Total: <span id="total">{{ session.total }}</span></p>#}
<form method="POST">
<label for="name">Name: </label><input type="name" id="name" name="name">
<label for="amount">Amount: </label><input type="amount" id="amount" name="amount">
<input type="submit" value="New Donation!">
</form>
{# <form method="POST" action="{{ url_for('save') }}">#}
{# <input type="submit" value="Save It!">#}
{# </form>#}
{% endblock content %}