def profile(): form = ProfileForm(obj=current_user) if form.validate_on_submit(): form.populate_obj(user) user.update_at = get_current_time() db.session.commit() flash('Public profile updated.', 'success') return render_template('user/profile.html', form=form)
def profile(): form = ProfileForm(obj=current_user) if form.validate_on_submit(): form.populate_obj(user) user.update_at = get_current_time() db.session.commit() flash('Public profile updated.', 'success') return render_template('user/profile.html', form=form)
def edit_profile(): form = ProfileForm() if form.validate_on_submit(): current_user.fullname = form.fullname.data current_user.location = form.location.data current_user.desc = form.desc.data db.session.add(current_user) db.session.commit() flash('You have modified your profile!') return redirect(url_for('user_profile', username=current_user.username)) form.fullname.data = current_user.fullname form.location.data = current_user.location form.desc.data = current_user.desc return render_template('user/edit_profile.html', form=form)
def profile(username): """ Creating the fucntion profile to process and display all the actions on profile page/template """ # Creating instances of Forms form = ProfileForm(username=username) form_tweet = Tweet() signup = Signup.query.filter_by(username=username).first() profile = Profile.query.filter_by(signup_id=signup.id).first() # Storing the photo urls profile_url = '/static/images/{}'.format(profile.profile_photo) header_url = '/static/images/{}'.format(profile.header_photo) # Logic for uploading photos and redirecting them after editing the profile if request.method == 'POST' and form.validate_on_submit(): try: profile_name = photos.save(request.files['profile_photo']) profile_url = '/static/images/{}'.format(profile_name) profile.profile_photo = profile_name except: pass try: header_name = photos.save(request.files['header_photo']) header_url = '/static/images/{}'.format(header_name) profile.header_photo = header_name except: pass signup.username = form.username.data profile.bio = form.bio.data profile.location = form.location.data profile.website = form.website.data db.session.commit() return redirect(url_for('profile', username=username)) # Find the total number of tweets total_likes = 0 tweets = Tweets.query.filter_by(username=username).order_by( Tweets.id.desc()).all() for tweet in tweets: total_likes = total_likes + tweet.likes users = Signup.query.filter(Signup.username != current_user.username).all() # finding the total number of followers and following and tweets total_attrib = [] total_attrib.append(len(tweets)) following = Following.query.filter_by(username=username).all() total_attrib.append(len(following)) followers = Followers.query.filter_by(username=username).all() total_attrib.append(len(followers)) # Displaying the 'who to follow' section and including 3 random real users in it display_users = [] if users: for i in range(3): temp = [] user = random.choice(users) signup_url = Signup.query.filter_by(username=user.username).first() user_url = '/static/images/{}'.format( signup_url.profile.first().profile_photo) temp.append(user) if Following.query.filter_by(username=current_user.username, following=user.username).first(): temp.append('Unfollow') else: temp.append('Follow') temp.append(user_url) display_users.append(temp) return render_template('timeline/profile.html', tweets=tweets, display_users=display_users, total_attrib=total_attrib, profile=profile, total_likes=total_likes, form=form, profile_url=profile_url, header_url=header_url, form_tweet=form_tweet)