def new_post(): form = PostForm() if form.validate_on_submit(): if form.image.data: picture = post_img(form.image.data) post = Post(title=form.title.data, content=form.content.data, anonymous=form.anonymous.data, image=picture, author=current_user) db.session.add(post) db.session.commit() flash('Your Post Has been Created!', 'success') return redirect(url_for('home')) else: post = Post(title=form.title.data, content=form.content.data, anonymous=form.anonymous.data, author=current_user) db.session.add(post) db.session.commit() flash('Your Post Has been Created!', 'success') return redirect(url_for('home')) return render_template('create_post.html', title='New Post', form=form, legend='New Post')
def home(): form = PostForm() if form.validate_on_submit(): if form.image.data: picture = save_picture(form.image.data) post = Post(title=form.title.data, content=form.content.data, image=picture, author=current_user) else: post = Post(title=form.title.data, content=form.content.data, author=current_user) db.session.add(post) db.session.commit() flash('Your Post Has been Created!', 'success') return redirect(url_for('home')) page = request.args.get('page', 1, type=int) posts = Post.query.order_by(Post.date_posted.desc()).paginate(per_page=50, page=page) users = User.query.all() if current_user.is_authenticated: image_file = url_for('static', filename='profile_pics/' + current_user.image_file) return render_template('home.html', title="Home", form=form, posts=posts, image_file=image_file, users=users) else: #return redirect(url_for('login')) return render_template('home.html', title="Home", posts=posts)
def home(): form = HomeForm() if form.validate_on_submit(): if form.image.data: picture = post_img(form.image.data) post = Post(title=form.title.data, content=form.content.data, anonymous=form.anonymous.data, image=picture, author=current_user) else: post = Post(title=form.title.data, content=form.content.data, anonymous=form.anonymous.data, author=current_user) db.session.add(post) db.session.commit() flash('Your Post Has been Created!', 'info') return redirect(url_for('home')) page = request.args.get('page', 1, type=int) posts = Post.query.order_by(Post.date_posted.desc()).paginate(per_page=20, page=page) users = User.query.all() suggested_friends = set() for user in users: if user != current_user and current_user.is_authenticated and not current_user.is_following( user): suggested_friends.add(user) if current_user.is_authenticated: image_file = url_for('static', filename='profile_pics/' + current_user.image_file) hour = datetime.now().hour greeting = "Good morning" if 5 <= hour < 12 else "Good afternoon" if hour < 18 else "Good evening" return render_template('home.html', title="Home", form=form, posts=posts, image_file=image_file, users=users, greeting=greeting, suggested_friends=suggested_friends) else: #return redirect(url_for('login')) return render_template('home.html', title="Home", posts=posts)
def new_post(): form = PostForm() if form.validate_on_submit(): post = Post(title=form.title.data, content=form.content.data, author=current_user) db.session.add(post) db.session.commit() flash('Your Post Has been Created!', 'success') return redirect(url_for('main.home')) return render_template('create_post.html', title='New Post', form=form, legend='New Post')