Ejemplo n.º 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="Главная")
Ejemplo n.º 2
0
def login():
    login_form = LoginForm()
    if login_form.validate_on_submit():
        user_name = login_form.username.data
        password = login_form.password.data
        users_model = UsersModel(db.get_connection())

        pwd = users_model.get(user_name=user_name)
        if pwd and pwd[0]:
            if check_password_hash(pwd[2], password):
                session['username'] = user_name
                session['user_id'] = pwd[0]
        return redirect("/index")
    return render_template('login.html', title='Авторизация', form=login_form)
Ejemplo n.º 3
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)
Ejemplo n.º 4
0
def sign_in():
    sign_in_form = SignInForm()
    if sign_in_form.validate_on_submit():
        user_name = sign_in_form.username.data
        password = generate_password_hash(sign_in_form.password.data)
        users_model = UsersModel(db.get_connection())
        if not users_model.get(user_name=user_name):

            user_id = users_model.insert(user_name, password)
            session['username'] = user_name
            session['user_id'] = user_id

            return redirect("/index")
    return render_template("sign_in.html",
                           title="Зарегестрироваться",
                           form=sign_in_form)
Ejemplo n.º 5
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)
Ejemplo n.º 6
0
def del_letters():
    if check(): return redirect('/login')
    user_model = UsersModel(db.get_connection())
    news_model = LetterModel(db.get_connection())
    news = news_model.get_all(session['username'])
    return render_template("del_letters.html",
                           title="Удалить Письма",
                           session=current_session,
                           news=news)
Ejemplo n.º 7
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)
Ejemplo n.º 8
0
def read_letter(letters_id):
    if check(): return redirect('/login')
    letters_model = LetterModel(db.get_connection())
    user_model = UsersModel(db.get_connection())
    new = letters_model.get(letters_id)
    print(new)
    return render_template("read_letters.html",
                           title="Удалить Письма",
                           session=current_session,
                           new=new)
Ejemplo n.º 9
0
def del_letter(letters_id):
    if check(): return redirect('/login')
    letters_model = LetterModel(db.get_connection())
    user_model = UsersModel(db.get_connection())
    new = letters_model.get(letters_id)

    if new:
        authors_id = new[3]
        if session['username'] == authors_id:
            letters_model.delete(letters_id)
    return redirect("/del_letters")
Ejemplo n.º 10
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="Новости друзей")
Ejemplo n.º 11
0
def del_new(news_id):
    if check(): return redirect('/login')

    news_model = NewsModel(db.get_connection())
    user_model = UsersModel(db.get_connection())
    new = news_model.get(news_id)

    if new:
        authors_id = new[3]
        if str(session["user_id"]) == "1" or int(
                session['user_id']) == authors_id:
            news_model.delete(news_id)
    return redirect("/del_news")