Skip to content

Commit

Permalink
fixes issue #66
Browse files Browse the repository at this point in the history
  • Loading branch information
Notabela committed Dec 15, 2017
1 parent b3c3a3b commit b6d098d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 13 deletions.
36 changes: 23 additions & 13 deletions camperapp/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from camperapp.models import db, CampEvent, CampGroup, CampEventSchema, Admin, Camper, Parent
from camperapp.forms import SignupFormAdmin, LoginForm, \
ChildEnrollmentForm, CreateParentForm, CreateChildForm
from flask import render_template, session, redirect, url_for, jsonify, request
from flask import render_template, session, redirect, url_for, jsonify, request, flash
from wtforms import SelectField
from wtforms.validators import DataRequired

Expand Down Expand Up @@ -140,30 +140,40 @@ def submit_parent_management():
def submit_camper_management():
"""EndPoint for Adding, Editing and Deleting a Camper"""
# a = request.get_json(force=True)
child_form = CreateChildForm(request.form) # Needs Testing
child_form = CreateChildForm(request.form)

# Search for Parent and Populate field
parent = Parent.query.filter_by(first_name=child_form.parent_first_name.data.lower(),
last_name=child_form.parent_last_name.data.lower()).first()
if not parent:
# Return and show an error
flash("Selected Parent does not exist", category='error')
return redirect(url_for('campers'))

# Add Validation Later
camper = Camper()
camper.first_name = child_form.first_name.data
camper.last_name = child_form.last_name.data
camper.birth_date = datetime.strptime(child_form.birth_date._value(), "%d %B, %Y")
camper.grade = child_form.grade.data
camper.gender = child_form.gender.data
camper.medical_notes = child_form.medical_notes.data
camper.street_address = child_form.street_address.data
camper.city = child_form.city.data
camper.state = child_form.state.data
camper.zip_code = child_form.zipcode.data

if child_form.street_address.data == "":
# No address supplied, set address to parent address
camper.street_address = parent.street_address
camper.city = parent.city
camper.state = parent.state
camper.zip_code = parent.zip_code

else:
camper.street_address = child_form.street_address.data
camper.city = child_form.city.data
camper.state = child_form.state.data
camper.zip_code = child_form.zipcode.data

camper.is_active = False
camper.group_id = int(child_form.group.data)

# Search for Parent and Populate field
parent = Parent.query.filter_by(first_name=child_form.parent_first_name.data.lower(),
last_name=child_form.parent_last_name.data.lower()).first()
if not parent:
return "<h1>Error</h1>"

camper.parent = parent

db.session.add(camper)
Expand Down
16 changes: 16 additions & 0 deletions camperapp/templates/admin_manage.html
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,22 @@ <h5>Please Enroll a Student</h5>
<script>
$(document).ready(function () {
//$('.tap-target').tapTarget('open');
{% with errors = get_flashed_messages(category_filter=["error"]) %}
{% if errors %}
{% for msg in errors %}
Materialize.toast('{{ msg }}', 4000);
{% endfor %}
{% endif %}
{% endwith %}

{# {% with messages = get_flashed_messages() %}#}
{# {% if messages %}#}
{# {% for message in messages %}#}
{# console.log(message);#}
{# {% endfor %}#}
{# {% endif %}#}
{#{% endwith %}#}

});
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/spectrum/1.8.0/spectrum.min.js"></script>
Expand Down

0 comments on commit b6d098d

Please sign in to comment.