def add_profile(): """Add a profile""" userid = g.user.get_id() form = UserProfileForm() if request.method == 'POST': if form.validate_on_submit(): username = request.form['username'].strip() firstname = request.form['firstname'].strip() lastname = request.form['lastname'].strip() sex = request.form['sex'] age = request.form['age'] image = request.files['img'] filename = "{}-{}".format(userid,secure_filename(image.filename)) filepath = "app/static/uploads/{}".format(filename) image.save(filepath) profile = Profile(username=username,userid=userid,firstname=firstname,lastname=lastname,image=filename,sex=sex,age=age,profile_added_on=datetime.now()) db.session.add(profile) db.session.commit() return redirect(url_for('view_profile',userid=userid)) user = db.session.query(Profile).filter(Profile.userid == userid).first() if user: return redirect(url_for('view_profile',userid=userid)) else: return render_template('addProfile.html', form=form)
def profile(): """Render the website's profile page.""" profilePage = UserProfileForm() if request.method == 'POST': if profilePage.validate_on_submit(): firstName = profilePage.firstName.data lastName = profilePage.lastName.data gender = profilePage.gender.data email = profilePage.email.data location = profilePage.location.data biography = profilePage.biography.data photo = profilePage.photo.data filename = secure_filename(photo.filename) photo.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) profile = Profile(first_name=firstName, last_name=lastName, gender=gender, email=email, location=location, biography=biography, profile_picture="uploads/" + filename) db.session.add(profile) db.session.commit() flash('New Profile Created!', 'success') return redirect(url_for('profiles')) else: flash_errors(profilePage) return render_template('profile.html', form=profilePage)
def profile(): userProfileForm = UserProfileForm() if request.method == "POST" and userProfileForm.validate_on_submit(): firstname = userProfileForm.fname.data lastname = userProfileForm.lname.data gender = userProfileForm.gender.data email = userProfileForm.email.data location = userProfileForm.location.data bio = userProfileForm.bio.data made_on = format_date_joined() photo = userProfileForm.photo.data image = secure_filename(photo.filename) photo.save(os.path.join(app.config['UPLOAD_FOLDER'], image)) user = UserProfile(first_name=firstname, last_name=lastname, gender=gender, email=email, location=location, bio=bio, image=image, created_on=made_on) db.session.add(user) db.session.commit() flash("Profile was successfully added", "success") return redirect(url_for("profiles")) flash_errors(userProfileForm) return render_template("profile.html", userProfileForm=userProfileForm)
def add_profile(): """Add a profile""" userid = g.user.get_id() form = UserProfileForm() if request.method == 'POST': if form.validate_on_submit(): username = request.form['username'].strip() firstname = request.form['firstname'].strip() lastname = request.form['lastname'].strip() sex = request.form['sex'] age = request.form['age'] image = request.files['img'] filename = "{}-{}".format(userid,secure_filename(image.filename)) filepath = "app/static/uploads/{}".format(filename) image.save(filepath) profile = Profile(username=username,userid=userid,firstname=firstname,lastname=lastname,image=filename,sex=sex,age=age,profile_added_on=datetime.now()) db.session.add(profile) db.session.commit() return redirect(url_for('view_profile',userid=userid)) user = db.session.query(Profile).filter(Profile.userid == userid).first() if user: return redirect(url_for('view_profile',userid=userid)) else: return render_template('addProfile.html', form=form)
def profile(): form = UserProfileForm() if request.method == 'POST' and form.validate_on_submit(): firstname = form.firstname.data lastname = form.lastname.data gender = form.gender.data #email = form.email.data location = form.location.data biography = form.biography.data display_pic = form.display_pic.data filename = secure_filename(display_pic.filename) display_pic.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) date_joined = format_date_join() newprofile = UserProfile(first_name=firstname, last_name=lastname, gender=gender, location=location, biography=biography, display_pic=filename) db.session.add(newprofile) db.session.commit() flash('Thank You For Joining Us!. Profile created..', 'success') return redirect(url_for('profiles')) else: flash_errors(form) return render_template('profile.html', form=form)