Beispiel #1
0
def show_all_articles():
    page = request.args.get('page', 1, type=int)
    per_page = current_app.config['ARTICLES_PER_PAGE']
    pagination = Article.query\
        .order_by(Article.id.desc())\
        .paginate(page, per_page=per_page, error_out=False)
    articles = pagination.items
    return render_template('index.html',
                           articles=articles,
                           endpoint='main.show_all_articles',
                           categories_list=Category.get_categories(),
                           pagination=pagination)
Beispiel #2
0
def show_followed_articles():
    if current_user.is_authenticated:
        page = request.args.get('page', 1, type=int)
        per_page = current_app.config['ARTICLES_PER_PAGE']
        pagination = current_user.followed_articles\
            .order_by(Article.id.desc())\
            .paginate(page, per_page=per_page, error_out=False)
        articles = pagination.items
        return render_template('index.html',
                               endpoint='main.show_followed_articles',
                               articles=articles,
                               categories_list=Category.get_categories(),
                               pagination=pagination)
    return redirect(url_for('.index'))
Beispiel #3
0
def show_category_articles(category_name):
    category_id = Category.query.filter_by(name=category_name).first().id
    page = request.args.get('page', 1, type=int)
    per_page = current_app.config['ARTICLES_PER_PAGE']
    pagination = Article.query\
        .join(Category, Article.category_id == Category.id)\
        .filter(Category.id == category_id)\
        .order_by(Article.id.desc())\
        .paginate(page, per_page=per_page, error_out=False)
    articles = pagination.items
    return render_template('index.html',
                           articles=articles,
                           endpoint='main.show_category_articles',
                           category_name=category_name,
                           categories_list=Category.get_categories(),
                           pagination=pagination)
Beispiel #4
0
def index():
    page = request.args.get('page', 1, type=int)
    per_page = current_app.config['ARTICLES_PER_PAGE']
    pagination = Article.query\
        .outerjoin(Comment)\
        .group_by(Article.id)\
        .order_by(desc(func.count(Comment.id)))\
        .paginate(page, per_page=per_page, error_out=False)
    articles = pagination.items
    context = {
        'articles': articles,
        'endpoint': 'main.index',
        'categories_list': Category.get_categories(),
        'pagination': pagination
    }
    return render_template('index.html', **context)