Example #1
0
 def post_detail(self, slug):
     cprint("YELLOW", "slug: |{}|".format(slug))
     post = Post.query.filter(Post.slug == slug).first_or_404()
     tags = post.tags
     return render_template('admin/post_detail.html',
                            pgname="post_detail",
                            company=Configuration.HTML_TITLE_COMPANY,
                            url_prefix='/{}'.format('admin'),
                            post=post,
                            tags=tags)
Example #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'})
Example #3
0
def index():
    if request.method == 'POST':
        title = request.form['title']
        body = request.form['body']

        try:
            post = Post(title=title, body=body)
            db.session.add(post)
            db.session.commit()
        except Exception as ex:
            cprint("RED", "Error: Post insert tk db. ex: {}".format(ex))

        return redirect(url_for('admin.index'))

    form = PostForm()
    q = request.args.get('q')

    page = request.args.get('page')
    if page and page.isdigit():
        page = int(page)
    else:
        page = 1

    if q:
        posts = Post.query.filter(Post.title.contains(q) | Post.body.contains(q))  # .all()
    else:
        # posts = Post.query.all()
        posts = Post.query.order_by(Post.created.desc())

    pages = posts.paginate(page=page, per_page=7)
    
    # print(posts.paginate)
    # for i in dir(pages):
    #     cprint("GREEN", "{}".format(i))
    #
    # cprint("YELLOW", pages.per_page)
    # cprint("PURPLE", pages.total)
    # for post in pages.items:
    #     cprint("GREEN", "pages: {}".format(post.body))

    return render_template("admin/home.html", pgname="Home", company=Configuration.HTML_TITLE_COMPANY, url_prefix='/{}'.format(admin_panel.name), form=form, pages=pages)