예제 #1
0
def create_post():
    form = NewPost()
    if form.validate_on_submit():
        postImage = ""
        if form.postImage.data:
            postImage = save_post_image(form.postImage.data)
        received_interests = request.form.getlist('check')
        interests_db = []
        for received_interest in received_interests:
            interest = db.session.query(Interest).filter_by(
                Title=received_interest).first()
            interests_db.append(interest)
        post = Post(Title=form.title.data,
                    Content=form.content.data,
                    ImageFile=postImage,
                    Author=current_user,
                    PostInterests=interests_db)
        db.session.add(post)
        db.session.commit()
        flash("Succesfully Posted!", category='success')
        return redirect(url_for('users.profile'))
    interests = Interest.query.all()
    return render_template('posts/create-post.html',
                           form=form,
                           interests=interests,
                           title="Make a story")
예제 #2
0
파일: routes.py 프로젝트: anoopkarnik/SNFE
def create_question_post():
    form = QuestionForm()
    if form.validate_on_submit():
        postImage = ""
        if form.postImage.data:
            postImage = save_post_image(form.postImage.data)
        post = Question(Title=form.title.data,
                        Content=form.content.data,
                        ImageFile=postImage,
                        Authorq=current_user)
        db.session.add(post)
        db.session.commit()
        flash("Succesfully Posted!", category='success')
        return redirect(url_for('main.question', order='time'))
    return render_template('question/create-question-post.html',
                           form=form,
                           title="Make a story")
예제 #3
0
파일: routes.py 프로젝트: anoopkarnik/SNFE
def create_living_post():
    form = LivingForm()
    if form.validate_on_submit():
        postImage = ""
        if form.postImage.data:
            postImage = save_post_image(form.postImage.data)
        post = Living(Title=form.title.data,
                      Content=form.content.data,
                      ImageFile=postImage)
        db.session.add(post)
        db.session.commit()
        flash("Succesfully Posted!", category='success')
        return redirect(url_for('main.living'))

    return render_template('living/create-living-post.html',
                           form=form,
                           title="Make a story")
예제 #4
0
def create_post():
    form = NewPost()
    if form.validate_on_submit():
        postImage = ""
        if form.postImage.data:
            postImage = save_post_image(form.postImage.data)
        post = Post(Title=form.title.data,
                    Content=form.content.data,
                    ImageFile=postImage,
                    Author=current_user)
        db.session.add(post)
        db.session.commit()
        flash("Succesfully Posted!", category='success')
        return redirect(url_for('users.profile'))

    return render_template('posts/create-post.html',
                           form=form,
                           title="Make a story")
예제 #5
0
def update_post(postID):
    post = Post.query.get_or_404(postID)
    if post.Author != current_user:
        abort(403)
    form = NewPost()
    if form.validate_on_submit():
        if form.postImage.data:
            postImage = save_post_image(form.postImage.data)
            post.ImageFile = postImage
        post.Title = form.title.data
        post.Content = form.content.data
        db.session.commit()
        return redirect(url_for('posts.post', postID=post.id))
    elif request.method == 'GET':
        form.title.data = post.Title
        form.content.data = post.Content
        form.postImage.data = post.ImageFile
    return render_template('posts/update-post.html',
                           title="Update Post",
                           form=form,
                           post=post)