Exemplo n.º 1
0
def update_post(post_id):
    post = Post.query.get_or_404(post_id)
    form = PostForm()
    if form.validate_on_submit():
        if form.picture.data:
            picture_file = save_picture(form.picture.data)
            post.image_file = picture_file
        post.city = form.city.data
        post.category = form.category.data
        post.title = form.title.data
        post.story = form.story.data
        post.summary = form.summary.data
        db.session.commit()
        flash(' post has been updated!', 'success')
        return redirect(url_for('posts.postn', post_id=post.id))
    elif request.method == 'GET':
        form.city.data = post.city
        form.category.data = post.category
        form.title.data = post.title
        form.story.data = post.story
        form.summary.data = post.summary
    return render_template('posts/create_post.html',
                           title='Update Post',
                           form=form,
                           legend='Update Post')
Exemplo n.º 2
0
def new_post():
    form = PostForm()
    if form.validate_on_submit():
        flash('Your post has been created!', 'success')
        hashtag = ''
        hashtags = form.content.data
        print(hashtags)
        newstr = hashtags.split()
        for char in newstr:
            if char.startswith("#"):
                hashtag = char.strip("#")
                print(hashtag)
                # if form.picture.data:
                #     picture_file = save_picture(form.picture.data)
                picture_file = save_picture(form.picture.data)
                # video_file = save_video(form.video.data )
                image = url_for('static', filename='images/' + picture_file)

                # video = url_for('static',filename='videos/'+video_file)

                post = Pitch(title=form.title.data,
                             content=form.content.data,
                             author=current_user,
                             hashtags=hashtag,
                             image=image)
                db.session.add(post)
                db.session.commit()
                return redirect(url_for('main.home'))

    return render_template('create_post.html',
                           title='New Post',
                           form=form,
                           legend='New Post')
Exemplo n.º 3
0
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():
        if form.picture.data:
            print('Hello World')
            picture_file = save_picture(form.picture.data)
            post.image_file = picture_file
        post.title = form.title.data
        post.content = form.content.data
        post.category = form.category.data
        post.summary = form.summary.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
        form.category.data = post.category
        form.summary.data = post.summary
    return render_template('create_post.html',
                           title='Update Post',
                           form=form,
                           legend='Update Post')
Exemplo n.º 4
0
def new_post():
    form = PostForm()
    if form.validate_on_submit():
        picture_file = '/static/background_pics/default.jpg'
        if form.picture.data:
            picture_file = save_picture(form.picture.data)
        post = Post(title=form.title.data,
                    content=form.content.data.replace('`', ''),
                    author=current_user,
                    image_file=picture_file)
        db.session.add(post)
        db.session.commit()
        flash('Your post has been created!', 'success')
        return redirect(url_for('main.root'))
    return render_template('create_post.html',
                           title='New Post',
                           form=form,
                           legend='New Post')
Exemplo n.º 5
0
def new_post():
    form = PostForm()
    picture_file = 'blog.jpg'
    if form.validate_on_submit():
        print(form.picture.data)
        if form.picture.data:
            picture_file = save_picture(form.picture.data)
        post = Post(title=form.title.data,
                    content=form.content.data,
                    category=form.category.data,
                    summary=form.summary.data,
                    image_file=picture_file,
                    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', form=form, legend="Create Post")
Exemplo n.º 6
0
def new_post(id):
    form = PostForm()
    user = User.query.get_or_404(id)
    if form.validate_on_submit():
        picture_file = save_picture(form.picture.data)
        post = Post(city=form.city.data,
                    image_file=picture_file,
                    category=form.category.data,
                    summary=form.summary.data,
                    title=form.title.data,
                    story=form.story.data,
                    Protagonist=user)
        db.session.add(post)
        db.session.commit()
        flash('Your Solution has been created!', 'success')
        return redirect(url_for('main.solutions'))
    return render_template('posts/create_post.html',
                           title='New Post',
                           form=form,
                           legend='Create Solution')
Exemplo n.º 7
0
def post(post_id):
    review = CommentForm()
    comments = Comment.query.all()
    post = Pitch.query.get_or_404(post_id)
    if review.validate_on_submit():
        # if review.picture.data:
        #             picture_file = save_picture(review.picture.data)

        # if review.video.data:
        #             video_file = save_video(review.video.data)
        picture_file = save_picture(review.picture.data)
        image = url_for('static', filename='images/' + picture_file)
        comment = Comment(body=review.comment.data,
                          post_id=post.id,
                          image_file=image)
        db.session.add(comment)
        db.session.commit()
        flash('Your post has been created!', 'success')
        return redirect(url_for('posts.post', post_id=post.id))
    return render_template('post.html',
                           title=post.title,
                           post=post,
                           review=review,
                           comments=comments)
Exemplo n.º 8
0
def new_post():
    form = PostForm()
    if form.validate_on_submit():
        if form.picture.data:
            picture_file = save_picture(form.picture.data)
            post = Post(title=form.title.data,
                        content=form.content.data,
                        author=current_user,
                        image_file=picture_file)
            db.session.add(post)
            db.session.commit()
        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('main.home'))
    return render_template('create_post.html',
                           title="New Post",
                           form=form,
                           legend='New Post')