Esempio n. 1
0
def user_posts(username):
    username = username.lower()
    if current_user.is_authenticated:
        form = UpdateAccountForm()
        if form.validate_on_submit():
            if form.picture.data:
                pic = profile_img(form.picture.data)
                current_user.dp = pic
            if form.picture2.data:
                pic2 = profile_img(form.picture2.data)
                current_user.dp2 = pic2
            if form.picture3.data:
                pic3 = profile_img(form.picture3.data)
                current_user.dp3 = pic3
            current_user.username = form.username.data.lower()
            if form.email.data:
                current_user.email = form.email.data
            current_user.snapchat = form.snapchat.data
            current_user.instagram = form.instagram.data
            current_user.department = form.department.data
            if form.student_number.data:
                current_user.student_number = form.student_number.data
            current_user.country = form.country.data
            current_user.age = form.age.data
            current_user.bio = form.bio.data
            current_user.private = form.private.data
            db.session.commit()
            flash('Your Account has been updated', 'success')
            return redirect(
                url_for('user_posts', username=current_user.username))
        elif request.method == 'GET':
            form.username.data = current_user.username
            form.email.data = current_user.email
            form.snapchat.data = current_user.snapchat
            form.instagram.data = current_user.instagram
            form.department.data = current_user.department
            form.student_number.data = current_user.student_number
            form.country.data = current_user.country
            form.age.data = current_user.age
            form.bio.data = current_user.bio
            form.private.data = current_user.private
        dp = url_for('static', filename='profile_pics/' + current_user.dp)
        user = User.query.filter_by(username=username).first_or_404()
        users = User.query.all()
        mutual = 0
        for person in user.followers:
            if user.is_following(person):
                mutual += 1
        return render_template('profile.html',
                               user=user,
                               users=users,
                               mutual=mutual,
                               title=user.username.title(),
                               dp=dp,
                               form=form)
    user = User.query.filter_by(username=username).first_or_404()
    return render_template('profile.html',
                           user=user,
                           title=user.username.title())
Esempio n. 2
0
def account():
    form = UpdateAccountForm()
    if form.validate_on_submit():
        if form.picture.data:
            pic = profile_img(form.picture.data)
            current_user.dp = pic
        if form.picture2.data:
            pic2 = profile_img(form.picture2.data)
            current_user.dp2 = pic2
        if form.picture3.data:
            pic3 = profile_img(form.picture3.data)
            current_user.dp3 = pic3
        current_user.username = form.username.data.lower()
        current_user.bio = form.bio.data
        current_user.email = form.email.data
        current_user.department = form.department.data
        current_user.student_number = form.student_number.data
        current_user.country = form.country.data
        current_user.age = form.age.data
        current_user.snapchat = form.snapchat.data
        current_user.instagram = form.instagram.data
        db.session.commit()
        flash('Your Account has been updated', 'success')
        return redirect(url_for('account'))
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.bio.data = current_user.bio
        form.email.data = current_user.email
        form.department.data = current_user.department
        form.student_number.data = current_user.student_number
        form.country.data = current_user.country
        form.age.data = current_user.age
        form.snapchat.data = current_user.snapchat
        form.instagram.data = current_user.instagram
    dp = url_for('static', filename='profile_pics/' + current_user.dp)
    return render_template('account.html', title='Account', dp=dp, form=form)