Beispiel #1
0
def drafts(page=1, sort='-created_at'):
	''' Lists of posts in admin view that are not published, paginated and sortable.'''
	form = SearchForm(request.form)
	posts = Post.objects(published=False).order_by(sort).paginate(page, per_page=6)
	if request.method == 'POST' and form.validate_on_submit():
		redirect(url_for('posts.drafts', page=page))
	return render_template("/admin/list.html",
		                   posts=posts,
		                   form=form,
		                   cur_endpoint=request.endpoint)
Beispiel #2
0
def drafts(page=1, sort='-created_at'):
    ''' Lists of posts in admin view that are not published, paginated and sortable.'''
    form = SearchForm(request.form)
    posts = Post.objects(published=False).order_by(sort).paginate(page,
                                                                  per_page=6)
    if request.method == 'POST' and form.validate_on_submit():
        redirect(url_for('posts.drafts', page=page))
    return render_template("/admin/list.html",
                           posts=posts,
                           form=form,
                           cur_endpoint=request.endpoint)
Beispiel #3
0
def search():
    search = SearchForm()
    if search.validate_on_submit():
        # reference for how to input the data into the like statement
        # accessed on 15/02/2021
        # https://stackoverflow.com/questions/3325467/sqlalchemy-equivalent-to-sql-like-statement
        query = "%{}%".format(search.query.data)
        # refernce for filtering multiple columns
        # accessed on 15/02/2021
        # https://stackoverflow.com/questions/3332991/sqlalchemy-filter-multiple-columns
        posts = Post.query.filter(db.or_(Post.title.like(query), Post.content.like(query)))
        return render_template('search.html', posts=posts, search=search)
    else:
        flash("I am afraid your search failed as it must contain letters or numbers without trailing spaces. Please try again.")
        return redirect(f'/allposts')