def create_post(): form = BlogPostForm() if form.validate_on_submit(): blog_post = BlogPost(title=form.title.data, text=form.text.data, user_id=current_user.id) db.session.add(blog_post) db.session.commit() flash("Blog Post Created") return redirect(url_for('core.index')) return render_template('create_post.html', form=form)
def update(blog_post_id): blog_post = BlogPost.query.get_or_404(blog_post_id) if blog_post.author != current_user: abort(403) form = BlogPostForm() if form.validate_on_submit(): if form.image.data: image = add_image_pic(form.image.data) s3_resource = boto3.resource('s3') my_bucket = s3_resource.Bucket(app.config['AWS_BUCKET']) my_bucket.Object(image).put(Body=form.image.data) test = 'https://{}.s3-ap-northeast-1.amazonaws.com/{}' images = test.format(app.config['AWS_BUCKET'], image) blog_post.event_image = images blog_post.title = form.title.data blog_post.text = form.text.data blog_post.event_date = form.event_date.data blog_post.event_time = form.event_time.data blog_post.organizer = form.organizer.data blog_post.place = form.place.data blog_post.entry = form.entry.data blog_post.way = form.way.data blog_post.cost = form.cost.data blog_post.contact = form.contact.data db.session.commit() flash("投稿を更新しました。") return redirect( url_for('blog_posts.blog_post', blog_post_id=blog_post.id)) elif request.method == 'GET': form.title.data = blog_post.title form.text.data = blog_post.text form.event_date.data = blog_post.event_date form.event_time.data = blog_post.event_time form.organizer.data = blog_post.organizer form.place.data = blog_post.place form.entry.data = blog_post.entry form.way.data = blog_post.way form.cost.data = blog_post.cost form.contact.data = blog_post.contact post_image = blog_post.event_image return render_template('create_post.html', title="Updating", form=form, post_image=post_image)
def create_post(): form = BlogPostForm() if form.validate_on_submit(): if form.image.data: image = add_image_pic(form.image.data) s3_resource = boto3.resource('s3') my_bucket = s3_resource.Bucket(app.config['AWS_BUCKET']) my_bucket.Object(image).put(Body=form.image.data) test = 'https://' + str(app.config['AWS_BUCKET'] ) + '.s3-ap-northeast-1.amazonaws.com/{}' images = test.format(image) blog_post = BlogPost(title=form.title.data, event_date=form.event_date.data, event_time=form.event_time.data, text=form.text.data, organizer=form.organizer.data, place=form.place.data, entry=form.entry.data, way=form.way.data, cost=form.cost.data, contact=form.contact.data, user_id=current_user.id, event_image=images) else: blog_post = BlogPost( title=form.title.data, event_date=form.event_date.data, event_time=form.event_time.data, text=form.text.data, organizer=form.organizer.data, place=form.place.data, entry=form.entry.data, way=form.way.data, cost=form.cost.data, contact=form.contact.data, user_id=current_user.id, event_image='https://' + str(app.config['AWS_BUCKET']) + '.s3-ap-northeast-1.amazonaws.com/default_profile.png') db.session.add(blog_post) db.session.commit() flash("投稿を作成しました!") return redirect(url_for('core.index')) return render_template('create_post.html', form=form, api=str(app.config['GOOGLE_MAP_API']))
def create(): """Creates a blog post""" form = BlogPostForm() if form.validate_on_submit(): blog_post = BlogPost(title=form.title.data, text=form.text.data, user_id=current_user.id, slug=form.title.data.strip().lower().replace( ' ', '-')) db.session.add(blog_post) db.session.commit() # creates and/or connects inputed tags with the post tags_from_string(form.tags.data, blog_post) flash('Blog post successfully created!', 'success') return redirect(url_for('core.index')) return render_template('create_post.html', form=form)
def update(blog_post_id): blog_post = BlogPost.query.get_or_404(blog_post_id) if blog_post.author != current_user: abort(403) form = BlogPostForm() if form.validate_on_submit(): blog_post.title = form.title.data blog_post.text = form.text.data db.session.commit() flash('Post Updated') return redirect( url_for('blog_posts.blog_post', blog_post_id=blog_post.id)) elif request.method == 'GET': form.title.data = blog_post.title form.text.data = blog_post.text return render_template('create_post.html', title='Update', form=form)
def update(blog_post_id): blog_post = BlogPost.query.get_or_404(blog_post_id) if blog_post.author != current_user: # Forbidden, No Access abort(403) form = BlogPostForm() if form.validate_on_submit(): blog_post.title = form.title.data blog_post.text = form.text.data db.session.commit() flash('Post Updated') return redirect(url_for('blog_posts.blog_post', blog_post_id=blog_post.id)) # Pass back the old blog post information so they can start again with # the old text and title. elif request.method == 'GET': form.title.data = blog_post.title form.text.data = blog_post.text return render_template('create_post.html', title='Update', form=form)