Exemple #1
0
def post_edit(id):
    post = Post.query.get(id)

    #prefill forum with with post object
    form = PostForm(obj=post)

    if form.validate_on_submit():

        print(" form title text")
        print(form.title.data)

        #populate from form to object fields
        form.populate_obj(post)

        #updating the time
        post.timestamp=datetime.now(timezone.utc)

        #update author 
        post.author_p = current_user


        print("done")
        #save the object
        post.save()

        flash("Post has been updated successfully" , 'success')
        return redirect(url_for('post.posts'))
    
    return render_template('admin/post/edit.html' , form=form , post= post)
Exemple #2
0
def post_edit(slug):
    cprint('YELLOW', 'REQUEST METHOD: {}'.format(request.method))
    post = Post.query.filter(Post.slug == slug).first_or_404()
    if request.method == 'GET':
        return jsonify({'status': 'ok', 'title': post.title, 'body': post.body})
    if request.method == 'POST':

        try:
            form = PostForm(formdata=request.form, obj=post)
            form.populate_obj(post)
            db.session.commit()
        except Exception as ex:
            PrintException(err_pth)
            return jsonify({'status': '[PYTHON] error: {}'.format(ex)})

        return jsonify({'status': 'ok'})