def add_profile(): """add a child profile""" form = ChildForm(request.form) app.logger.debug(form.validate()) app.logger.debug(form.errors) if request.method == 'POST' and form.validate(): # get all new data # Upload image # import pdb; pdb.set_trace() file = request.files['file'] imgroot = '' if file and allowed_file(file.filename): print "This should be the file: ", file filename = secure_filename(file.filename) file.save(os.path.join("app/", app.config['UPLOAD_FOLDER'], filename)) # Save the image path to send to the database imgroot = os.path.join("/", app.config['UPLOAD_FOLDER'], filename) # Get all the other contents first_name = form.data['first_name'] last_name = form.data['last_name'] birth_date = form.data['birth_date'] guardian_type = form.data['guardian_type'] guardian_fname = form.data['guardian_fname'] guardian_lname = form.data['guardian_lname'] godparent_prefix = form.data['godparent_prefix'] godparent_fname = form.data['godparent_fname'] godparent_lname = form.data['godparent_lname'] godparent_email = form.data['godparent_email'] medical_condition = form.data['medical_condition'] doctor_appt = form.data['doctor_appt'] situation = form.data['situation'] home_visit = form.data['home_visit'] latitude = form.data['latitude'] longitude = form.data['longitude'] activity = True # seed into database child_entry = Child(pic_url=imgroot, first_name=first_name, last_name=last_name, birth_date=birth_date, guardian_type=guardian_type, guardian_fname=guardian_fname, guardian_lname=guardian_lname, godparent_prefix=godparent_prefix, godparent_fname=godparent_fname, godparent_lname=godparent_lname, godparent_email=godparent_email, medical_condition=medical_condition, doctor_appt=doctor_appt, situation=situation, home_visit=home_visit, latitude=latitude, longitude=longitude, activity=activity) db.session.add(child_entry) db.session.commit() child = db.session.query(Child).order_by(Child.id.desc()).first() return redirect('/child/%d' % child.id) else: return render_template('add_profile.html', form=form)
def edit_profile(id): """ Edit child profile """ child = db.session.query(Child).filter_by(id=id).first() if child is None: abort(404) form = ChildForm(request.form) if request.method == 'POST' and form.validate(): # update child info from edit_profile.html form # Set pic_url to empty string to keep original path in case no changes are made. pic_url = "" file = request.files['file'] # print "This should be the file: ", file if file and allowed_file(file.filename): # If no image is uploaded, this never passes. filename = secure_filename(file.filename) file.save(os.path.join("app/", app.config['UPLOAD_FOLDER'], filename)) # Save the image path to send to the database pic_url = os.path.join("/", app.config['UPLOAD_FOLDER'], filename) # get all new data # pic_url = request.form.get("file") app.logger.debug("inside this code") # seed into database if pic_url != "": child.pic_url = pic_url # print "This should be a pic path: ", pic_url child.first_name = form.data['first_name'] child.last_name = form.data['last_name'] child.birth_date = form.data['birth_date'] child.guardian_type = form.data['guardian_type'] child.guardian_fname = form.data['guardian_fname'] child.guardian_lname = form.data['guardian_lname'] child.godparent_prefix = form.data['godparent_prefix'] child.godparent_fname = form.data['godparent_fname'] child.godparent_lname = form.data['godparent_lname'] child.godparent_email = form.data['godparent_email'] child.medical_condition = form.data['medical_condition'] child.doctor_appt = form.data['doctor_appt'] child.situation = form.data['situation'] child.home_visit = form.data['home_visit'] child.latitude = form.data['latitude'] child.longitude = form.data['longitude'] db.session.commit() return redirect('/child/%d' % child.id) return render_template('edit_profile.html', form=form, child=child)