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 post.service = form.service.data post.category = form.category.data post.location=Post.point_representation(form.lat.data, form.lng.data) db.session.commit() flash('Your post has been updated!', 'success') return redirect(url_for('posts.post', post_id=post.id)) elif request.method == 'GET': form.title.data = post.title form.content.data = post.content post.service = form.service.data post.category = form.category.data return render_template('create_post.html', title='Update Post', form=form, legend='Update Post')
def new_post(): form = PostForm() if form.validate_on_submit(): print(dir(form.service.data)) post = Post( title=form.title.data, content=form.content.data, location=Post.point_representation(form.lat.data, form.lng.data), user_id=current_user.id, type_of_service=int(form.service.data), # Take numeric id of choice category=form.category.data) db.session.add(post) db.session.commit() flash('Your post has been created!', 'success') return redirect(url_for('main.home')) else: # This will help you see in the console if the form was submitted but 'does nothing' # what is wrong with it for field, errors in form.errors.items(): print("Form has errors:", field, ', '.join(errors)) return render_template('create_post.html', title='New Post', form=form, legend='New Post')