def profile_post(): form = ProfileForm(request.form) #print request.form if form.validate(): #get the user from the database session user = current_user # do not store the results of calculations using variable defined in # models.py That is what models.py is for. user.calorie_goal = form.calorie_goal.data user.protein_goal = form.protein_goal.data #what about user.amino_acid_goals? #Institute of Medicine's Food and Nutrition Board # Essential Amino Acid Needed per g of Protein Needed for 50g of Protein # Trytophan 7mg/.007g .35g # Threonine 27mg/.027g 1.35g # Isoleucine 25mg/025g 1.25g # Leucine 55mg/.055g 2.76g # Lysine 51mg/.051g 2.56g # Methionine+Cystine 25mg/.025g 1.25g # Phenylalanine+Tyrosine 47mg/.047g 2.36g # Valine 32mg/.032g 1.60g # Histidine 18mg/.018g .90g #age of user determines multiplier of x times kg of weight # 1.5g per kg - infants # 1.1g per kg - 1-3 years # .95g per kg - 4-13 years # .85g per kg - 14-18 years # .80g per kg - adults # 1.1g per kg - pregnant and lactating women user.carbohydrate_goal = form.carbohydrate_goal.data user.fat_goal = form.fat_goal.data #user.nutrient_goal = form.nutrient_goal.data user.birthday = form.birthday.data user.set_weight(form.weight.data, form.weight_unit.data) #user.set_weight_goal(form.weight_goal.data, form.weight_unit.data) user.set_height(form.height_in_centimeters.data / 100) user.gender = form.gender.data user.activity_level = form.activity_level.data user.set_weekly_weight_change(form.weekly_change_level.data) session.commit() #Here we need to save the information enterred by the User. #need access to the user object. #return redirect(url_for('profile_get')) flash("You have successfully enterred your Profile Information.") flash("Select Foodlog to continue.") return render_template( 'profile.html', title='Profile', form=form, text= 'Either stay on your Profile or go to the Home, Foodlog or Logout Page.', ) else: flash("Try again") print form.errors return render_template('profile.html', title='Profile', form=form)
def profile(): form = ProfileForm(CombinedMultiDict((request.files, request.form))) if request.method == 'POST': avatar_path = '' if form.validate(): image = form.avatar.data intro = form.intro.data github_url = form.github_url.data linkedin_url = form.linkedin_url.data avatar_path = secure_filename(image.filename) uploaded_file = Path( current_app.config.get('UPLOAD_FOLDER')) / avatar_path image.save(str(uploaded_file)) form.avatar_path.data = avatar_path kw = { 'intro': intro, 'github_url': github_url, 'linkedin_url': linkedin_url } if avatar_path: kw.update(avatar=avatar_path) set_profile(**kw) if not avatar_path: form.avatar_path.data = get_profile().avatar elif request.method == 'GET': profile = get_profile() form.intro.data = profile.intro form.github_url.data = profile.github_url form.avatar_path.data = profile.avatar return render_template('admin/profile.html', form=form)
def addProfile(): profileform = ProfileForm() if request.method == "POST" and profileform.validate(): if profileform.validate_on_submit(): first_name = profileform.first_name.data last_name = profileform.last_name.data gender = profileform.gender.data email = profileform.email.data location = profileform.location.data bio = profileform.bio.data photo = profileform.photo.data photo_filename = secure_filename(photo.filename) photo.save(os.path.join(app.config['UPLOAD_FOLDER'], photo_filename)) profile = UserProfile(first_name,last_name,gender,location, email,bio, photo_filename) db.session.add(profile) db.session.commit() # photo.save(os.path.join(app.config)) flash('User sucessfully added', 'success') return redirect(url_for('profiles')) else: return render_template('addProfile.html', form = profileform) if request.method =="GET": return render_template('addProfile.html')
def settings(): form = ProfileForm(request.form, current_user) if request.method == 'POST' and form.validate(): form.populate_obj(current_user) current_user.password = encrypt_password(current_user.password) db.session.commit() return redirect('/') else: return render_template('profile.html', form=form, profile=current_user)
def test_changing_email_to_dupe_is_invalid(self): jojo = User(nickname='jojo', email='*****@*****.**') db.session.add(jojo) abobo = User(nickname='abobo', email='*****@*****.**') db.session.add(abobo) db.session.commit() with app.app_context(): form = ProfileForm(jojo.email) form.email.data = abobo.email self.assertFalse(form.validate()) self.assertGreater(len(form.email.errors), 0) self.assertNotEquals( str(form.email.errors[0]).find( "This e-mail address is already in use. Please provide a different one." ), -1)
def profile_post(): form = ProfileForm(request.form) #print request.form if form.validate(): #get the user from the database session user = current_user # do not store the results of calculations using variable defined in # models.py That is what models.py is for. user.calorie_goal = form.calorie_goal.data user.protein_goal = form.protein_goal.data #what about user.amino_acid_goals? #Institute of Medicine's Food and Nutrition Board # Essential Amino Acid Needed per g of Protein Needed for 50g of Protein # Trytophan 7mg/.007g .35g # Threonine 27mg/.027g 1.35g # Isoleucine 25mg/025g 1.25g # Leucine 55mg/.055g 2.76g # Lysine 51mg/.051g 2.56g # Methionine+Cystine 25mg/.025g 1.25g # Phenylalanine+Tyrosine 47mg/.047g 2.36g # Valine 32mg/.032g 1.60g # Histidine 18mg/.018g .90g #age of user determines multiplier of x times kg of weight # 1.5g per kg - infants # 1.1g per kg - 1-3 years # .95g per kg - 4-13 years # .85g per kg - 14-18 years # .80g per kg - adults # 1.1g per kg - pregnant and lactating women user.carbohydrate_goal = form.carbohydrate_goal.data user.fat_goal = form.fat_goal.data #user.nutrient_goal = form.nutrient_goal.data user.birthday = form.birthday.data user.set_weight(form.weight.data, form.weight_unit.data) #user.set_weight_goal(form.weight_goal.data, form.weight_unit.data) user.set_height(form.height_in_centimeters.data / 100) user.gender = form.gender.data user.activity_level = form.activity_level.data user.set_weekly_weight_change(form.weekly_change_level.data) session.commit() #Here we need to save the information enterred by the User. #need access to the user object. #return redirect(url_for('profile_get')) flash("You have successfully enterred your Profile Information.") flash("Select Foodlog to continue.") return render_template( 'profile.html', title='Profile', form=form, text='Either stay on your Profile or go to the Home, Foodlog or Logout Page.', ) else: flash("Try again") print form.errors return render_template( 'profile.html', title='Profile', form=form)