Exemplo n.º 1
0
def admin_only():
    if 'username' not in session:
        return redirect('/login')
    news = NewsModel(news_db.get_connection()).get_all()
    news.sort(key=lambda x: x[3])
    return render_template('index.html',
                           username=session['username'],
                           news=news)
Exemplo n.º 2
0
def admin_only():
    if 'username' not in session:
        return redirect('/login')
    news = NewsModel(news_db.get_connection()).get_all()
    news.sort(key=lambda x: x[3])
    user_model = UsersModel(users_db.get_connection())
    usernames = {}
    for item in news:
        data = user_model.get(item[4])
        if item[4] not in usernames:
            usernames.update(
                {item[4]: [str(data[2] + ' ' + data[3]), data[1]]})
    return render_template('index.html',
                           username=session['username'],
                           news=news,
                           users=usernames)
Exemplo n.º 3
0
def sort_by(sort):
    if 'username' not in session:
        return redirect('/login')
    nm = NewsModel(db.get_connection())
    news = nm.sort(sort, user_id=session['user_id'])
    return render_template('index.html',
                           username=session['username'],
                           news=news)
Exemplo n.º 4
0
def index():
    if 'username' not in session:
        return redirect('/ban')
    news = NewsModel(news_db.get_connection()).get_all(session['user_id'])
    news.sort(key=lambda x: x[3])
    news.reverse()
    user_model = UsersModel(users_db.get_connection())
    usernames = {}
    for item in news:
        data = user_model.get(item[4])
        if item[4] not in usernames:
            usernames.update(
                {item[4]: [str(data[2] + ' ' + data[3]), data[1]]})

    return render_template('index.html',
                           title='a',
                           username=session['username'],
                           cur_user_id=session['user_id'],
                           news=news,
                           users=usernames)