Exemple #1
0
def index():
    if check(): return redirect('/login')
    users_model = UsersModel(db.get_connection())
    news_model = LetterModel(db.get_connection())
    news = news_model.get_all(session['username'])
    for a in range(len(news)):
        news[a] = list(news[a])
        news[a][4] = users_model.get_name(news[a][4])
    return render_template('index.html',
                           username=session['username'],
                           news=news,
                           session=current_session,
                           title="Главная")
Exemple #2
0
def del_news():
    if check(): return redirect('/login')

    user_model = UsersModel(db.get_connection())
    news_model = NewsModel(db.get_connection())
    lambda_for_jinja = lambda x: [x[1], user_model.get_name(x[3]), x[0]]
    if str(session['user_id']) == '1':
        news = list(map(lambda_for_jinja, news_model.get_all()))
    else:
        news = list(
            map(lambda_for_jinja, news_model.get_all(session['user_id'])))
    return render_template("del_news.html",
                           title="Удалить новости",
                           session=current_session,
                           news=news)
Exemple #3
0
def users_list():
    if check(): return redirect('/login')

    friends_model = FriendsModel(db.get_connection())
    users_model = UsersModel(db.get_connection())

    check_friendship = lambda x: not friends_model.check_friendship(
        session['user_id'], x)
    users_ids = users_model.get_all_ids()

    users = filter(check_friendship, users_ids)
    users = list(map(lambda x: [users_model.get_name(x), x], users))
    return render_template("users_list.html",
                           title="С кем бы подружиться?",
                           users=users,
                           session=current_session)
Exemple #4
0
def friends_list():
    if check(): return redirect('/login')

    friends_model = FriendsModel(db.get_connection())
    users_model = UsersModel(db.get_connection())
    friends_ids = friends_model.get_friends(session['user_id'])

    if friends_ids and str(session['user_id']) != "1":
        friends = map(lambda x: [users_model.get_name(x[2]), x[2]],
                      friends_ids)
        return render_template("friends_list.html",
                               title="Мои друзья",
                               friends=friends,
                               session=current_session)
    return render_template("friends_list.html",
                           title="Мои друзья",
                           friends=None,
                           session=current_session)
Exemple #5
0
def index():
    if check(): return redirect('/login')

    users_model = UsersModel(db.get_connection())
    friends_model = FriendsModel(db.get_connection())

    friends_ids = list(
        map(lambda x: x[2], friends_model.get_friends(session['user_id'])))

    news = []
    for friend_id in friends_ids:
        news += get_news(friend_id)

    if news:
        news = map(lambda x: [users_model.get_name(x[0]), x[1], x[2]], news)
    return render_template('index.html',
                           username=session['username'],
                           news=news,
                           session=current_session,
                           title="Новости друзей")