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('home')) return render_template('create_post.html', title='New Post', form=form, legend='New Post')
def new_post(): form = PostForm() if form.validate_on_submit(): post = Post(title=form.title.data, content=form.content.data, bg=form.bg.data, author=current_user) db.session.add(post) db.session.commit() flash('your post has successfully posted.', 'success') return redirect(url_for('posts.new_post')) return render_template('create_post.html', title='new_post', form=form, legend='create post')
def update_post(post_id): post = Post.query.get_or_404(post_id) if post.author != current_user: abort(403) form = PostForm() if form.validate_on_submit(): post.title = form.title.data post.content = form.content.data db.session.commit() form.title.data = post.title form.content.data = post.content return render_template('new_post.html', title='Update Post', form=form, legend='Update Post')
def new_post(): form = PostForm() if form.validate_on_submit(): post = Post(client_name=form.client_name.data, client_or_saggezza=form.client_or_saggezza.data, client_project=form.client_project.data, date=form.date.data, billable_to=form.billable_to.data, payment=form.payment.data, receipt=form.receipt.data, category=form.category.data, description=form.description.data, GBP=form.GBP.data, EUR=form.EUR.data, USD=form.USD.data, author=current_user) post.verify_or_decline = 'pending' if form.picture.data: picture_file = save_picture(form.picture.data) current_user.receipt_file = picture_file db.session.add(post) db.session.commit() flash('Expense has been created!', 'success') return redirect(url_for('home')) return render_template('create_post.html', title='New Post', form=form, legend='New Post')
def update_post(post_id): post = Post.query.get_or_404(post_id) if post.user_id != current_user.id: abort(403) form = PostForm() if form.validate_on_submit(): #Deal with post method post.title = form.title.data post.content = form.content.data db.session.commit() flash('Post updated successfully','success') return redirect(url_for('post',post_id = post.id)) elif request.method == 'GET': #Deal with get method form.title.data = post.title form.content.data = post.content return render_template('create_post.html',title = 'Update Post', form = form, legend = 'Update Post')
def update_post(post_id): post = Post.query.get_or_404(post_id) if post.author != current_user: abort(403) form = PostForm() if form.validate_on_submit(): # Check if the user is logged in or not post.title = form.title.data # To Update Post Title post.content = form.content.data # To Update Post Content db.session.commit() flash ('Your post has been updated!', 'success') # Flash a message return redirect(url_for('post', post_id=post.id)) elif request.method == 'GET': form.title.data = post.title # Populate the input field form.content.data = post.content # Populate the input field return render_template('create_post.html', title='Update Post', form=form, legend='Update Post')
def new_post(): form = PostForm() if form.validate_on_submit(): post = Post(title = form.title.data, location = form.location.data, phone_no = form.phone_no.data, content= form.content.data, author= current_user) print('Location', file=sys.stderr) print(form.location.data, file=sys.stderr) geolocator = Nominatim(user_agent="app") location = geolocator.geocode(form.location.data) print(location.latitude, location.longitude, file=sys.stderr) post.location2 = str(location.latitude)+','+str(location.longitude) 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)
def new_post(): form = PostForm() if form.validate_on_submit(): # Adding the data entered in new post form into the database. 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')) return render_template('create_post.html', title='New Post', form=form, legend="New Post")
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(f"Your post has been created!", 'success') return redirect(url_for('index')) return render_template('create_post.html', title='New Post', form=form, legend='New Post')
def new_post(): form = PostForm() if form.validate_on_submit(): #Here we have used author as a back reference to author of the post (check out models.py for details) post = Post(title=form.title.data, content=form.content.data, author=current_user) db.session.add(post) db.session.commit() flash("Post Created!", "success") return redirect(url_for('home')) return render_template('create_post.html', title='New Post', form=form, legend='Update Post')
def post_update(post_id): form = PostForm() post=Post.query.get_or_404(post_id)# if doesnt exist then 404 if post.author.username!=current_user.username: abort(403)# forbidden operation if form.validate_on_submit(): post.title=form.title.data post.content=form.content.data db.session.commit() flash('Your post has been updated','success') return redirect(url_for('post',post_id=post.id)) elif request.method=='GET': form.title.data = post.title form.content.data = post.content return render_template('create_post.html', form=form,legend="Update Post")
def update_post(post_id): post = Post.query.get_or_404(post_id) if post.author !=current_user: abort(403) form = PostForm() if form.validate_on_submit(): post.title = form.title.data post.content = form.content.data db.session.commit() flash('Your post has been updated!', 'success') return redirect(url_for('post', post_id=post.id)) elif request.method == 'GET': form.title.data = post.title form.content.data = post.content return render_template('create_post.html', title='Update Post', form=form, legend='Update Post')
def update_post(post_id): post = Post.query.get_or_404(post_id) if post.author != current_user: abort(403) form = PostForm() if form.validate_on_submit(): post.title = form.title.data post.content = form.content.data db.session.commit() flash("Your post has been updated") return redirect(url_for("post", post_id=post.id)) elif request.method == "GET": form.title.data = post.title form.content.data = post.content return render_template("create_post.html", title = "Update Post", form=form, legend="Update Post")
def edit_post(post_id): form = PostForm() post = Post.query.get_or_404(post_id) # 先从数据库拿到post对象 if form.validate_on_submit(): post.title = form.title.data post.body = form.body.data post.category = Category.query.get(form.category.data) db.session.commit() # 注意!flask SQLAlchemy修改数据时不需要添加db.session.add()语句 flash('更新文章成功!', 'success') # 编辑完后回到显示该文章内容页面 return redirect(url_for('my_blog.show_post', post_id=post.id)) form.title.data = post.title form.body.data = post.body form.category.data = post.category_id return render_template('admin/edit_post.html', form=form)
def new_post(): """Create new post""" form = PostForm() if form.validate_on_submit(): post = Post(title=form.title.data, content=form.content.data, author=current_user, topic_id=form.topic.data) 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 update_post(post_id): form = PostForm() post= Post.query.get(post_id) if current_user != post.author: abort(403) if form.validate_on_submit(): post.title= form.title.data post.description = form.description.data #db.session.add(post) db.session.commit() flash('Your Post has been updated','success') return redirect(url_for('index')) elif request.method == 'GET': form.title.data = post.title form.description.data = post.description return render_template('create_post.html',title=f'Update Post {post_id}', form = form, heading = 'Update Post')
def new_post(): form = PostForm() if form.validate_on_submit(): # post = Post(title=form.title.data, content=form.content.data, user_id=current_user.id) post = Post(title=form.title.data, content=form.content.data, date_posted=datetime.utcnow(), author=current_user) db.session.add(post) db.session.commit() flash('Post added Sucessfully!', 'success') return redirect(url_for('home')) return render_template('create_post.html', title='New Post', form=form, legend='Create Post')
def update_post(post_id): post = Post.query.get_or_404(post_id) #if the post with that id doesn't exist-> 404 if post.author != current_user: abort(403) form = PostForm() if form.validate_on_submit(): post.title = form.title.data post.content = form.content.data db.session.commit() flash('Your post has been updated', 'success') return redirect(url_for('post', post_id=post.id)) #redirect specific post elif request.method == 'GET': #Fill form with old title/content form.title.data = post.title form.content.data = post.content return render_template('create_post.html', title='Update Post', form=form, legend='Updated Post')
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 successfully published !', 'success') return redirect(url_for('hello')) return render_template('newpost.html', title='New Post', form=form, legend='New Post')
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!", category="success") return redirect(url_for("home")) return render_template("create_post.html", title="New Post", form=form, legend="New Post")
def new_post(): form = PostForm() if form.validate_on_submit(): post = Post(title=form.title.data, content=form.content.data, author=current_user, category=form.category.data, programming_language=form.programming_language.data) 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 new_post(): form = PostForm() if form.validate_on_submit(): post = Post3(title=form.title.data, content=form.content.data, author=current_user.username, user_id=current_user.id, image_file=current_user.image_file) 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 Notification')
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('发帖成功', 'success') return redirect(url_for('home')) return render_template('create_post.html', title='新帖子', form=form, legend='新帖子')
def update_post(post_id): post = Post.query.get_or_404(post_id) if post.author != current_user: abort(403) form = PostForm() if form.validate_on_submit(): post.title = form.title.data post.content = form.content.data db.session.commit() flash('Your post has been updated!', 'success') return redirect(url_for('post', post_id=post.id)) elif request.method == 'GET': form.title.data = post.title form.content.data = post.content return render_template('create_post.html', title='Update Post', form=form, legend='Update Post')
def new_post(): #if current_user.is_authenticated: # print("aaaaaa") 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('home')) return render_template('create_post.html', title='New Post', form=form, legend='New Post')
def new_post(): form = PostForm() if form.validate_on_submit(): audio_file = save_audio(form.audio.data) post = Post(title=form.title.data, content=form.content.data, author=current_user, voice=audio_file) 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 update_post(post_id): post = Post.query.get_or_404(post_id) if post.author != current_user: abort(403) # http response for a forbidden route form = PostForm() if form.validate_on_submit(): post.title = form.title.data post.content = form.content.data db.session.commit() # don't need to use db.session since the data is already in the database flash('Your post has been updated!', 'success') return redirect(url_for('post', post_id=post.id)) elif request.method == 'GET': form.title.data = post.title form.content.data = post.content return render_template('create_post.html', title='Update Post', form=form, author=current_user, legend='Update Post')
def new_post(): form = PostForm() if not current_user: return redirect(url_for('main.login')) if form.validate_on_submit(): new_post = Post(id=str(uuid4()), title=form.title.data) new_post.text = form.text.data new_post.publish_date = datetime.now() db.session.add(new_post) db.session.commit() return redirect(url_for('blog.home')) return render_template('new_post.html', form=form)
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 had been created!', 'success') # Success is the bootstrap class to make it prettier. return redirect(url_for('home')) return render_template('create_post.html', title='New Post', form=form, legend='New Post')
def new_post(): form = PostForm() #model-picture/form-image if form.validate_on_submit(): print(form.image.data) #picture = images.save(form.image.data)#return filename #post = Post(title=form.title.data, content=form.content.data, author=current_user, picture = picture) ##picture = url_for('static', filename='profile_pics/' + post.picture)## #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') ###image_file=image_file
def new_post(): form = PostForm() if form.validate_on_submit(): post = Post(title=form.title.data, content=form.content.data, author=current_user, access=form.target_class.data) 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', access=STUDENT_CODE)
def new_post(): form = PostForm() if form.validate_on_submit(): post = Post(title=form.title.data, content=form.content.data, user_id=current_user.id, category_id=Category.query.filter_by( category_name=form.category.data).first().id) db.session.add(post) db.session.commit() flash('Your post has been creared!', 'success') return redirect(url_for('home')) return render_template('create_post.html', title='New Post', form=form, legend='New Post')