def add_post(): form = NewPostForm() if form.validate_on_submit(): post = Post() form.populate_obj(post) db.session.add(post) db.session.commit() return redirect('/') return render_template('add_post.html', form = form)
def post_page(): form = NewPostForm() if form.validate_on_submit(): post = Post() form.populate_obj(post) db.session.add(post) db.session.commit() return redirect("/post_page") return render_template("post_page.html", form=form)
def add_post(): form = NewPostForm() if form.validate_on_submit(): post = Post() form.populate_obj(post) post.author_id = current_user.id db.session.add(post) db.session.commit() return redirect('/') return render_template("add_post.html", form=form)
def add_post(): form = NewPostForm() if form.validate_on_submit(): post = Post() form.populate_obj(post) post.author_id = current_user.id db.session.add(post) db.session.commit() return redirect('/') return render_template("add_post.html", form = form)
def pathway(): form = NewPostForm() if form.validate_on_submit(): post = Post() form.populate_obj(post) db.session.add(post) db.session.commit() return redirect('/pathway') users = User.query.all posts = Post.query.filter_by(topic='pathway') return render_template('pathway.html', form=form, users=users, posts=posts)
def Undocuqueer(): form = NewPostForm() #calling on NewPostForm from forms.py if form.validate_on_submit( ): #if statement: saying the if the submit button is pushed then, post = Post() #it prepares a new row for the info to be passed in form.populate_obj(post) #then populates new post info entered by user db.session.add(post) #creates new post db.session.commit() #after it is submitted, it redirects back to the, return redirect('/Undocuqueer') #Undocuqueer page users = User.query.all #This GETs users to show on the page posts = Post.query.filter_by( topic='Undocuqueer') #with post filtered by the topic return render_template('Undocuqueer.html', form=form, users=users, posts=posts)
def edit_post(post_id): post = session.query(Post).filter_by(id=post_id).one() creator = session.query(User).filter_by(id=post.user_id).one() # Populate the form from the data form = NewPostForm(obj=post) # only creator of the post can edit it if login_session['user_id'] != creator.id: login_session.pop('_flashes', None) flash('You do not have authorization to edit this post!') return redirect(url_for('view_post', post_id=post_id)) if form.validate_on_submit(): old_img = post.attached_img form.populate_obj(post) post.get_short_content() post.last_modified = time() if form.image.data and allowed_file(form.image.data.filename): # if there's previoused attached image if old_img: # first delete the previous file in the upload_folder deleting_file = os.path.join(app.config['UPLOAD_FOLDER'], old_img) os.remove(deleting_file) # then upload the new file file = form.image.data # save file with prefix(blog_id) and suffix(last_modified time) post.attached_img = upload(file, str(login_session['blog_id']), str(int(post.last_modified))) session.add(post) session.commit() return redirect(url_for('view_post', post_id=post_id)) print form.errors return render_template('post.html', form=form, post=post, user_id=login_session.get('user_id'), username=login_session.get('username'), action=url_for('edit_post', post_id=post.id))