Beispiel #1
0
def my_page():
    if 'username' not in session:
        return redirect('/login')
    if request.method == 'GET':
        nm = NewsModel(db.get_connection())
        nm.init_table()
        um = UsersModel(db.get_connection())
        um.init_table()
        em = um.get_email(session['username'])
        uname = session['username']
        image = um.get_avatar(uname)
        return render_template('account.html',
                               username=uname,
                               news=nm.get_all(uname),
                               email=em,
                               own="True",
                               image=image)
Beispiel #2
0
def show_user(uname):
    if 'username' not in session:
        return redirect('/login')
    nm = NewsModel(db.get_connection())
    nm.init_table()
    um = UsersModel(db.get_connection())
    um.init_table()
    em = um.get_email(session['username'])
    image = um.get_avatar(uname)
    if uname == session['username']:
        owning = 'True'
    else:
        owning = 'False'
    if request.method == "GET":
        print(nm.get_all(uname))
        return render_template('account.html',
                               username=uname,
                               news=nm.get_all(uname),
                               email=em,
                               own=owning,
                               image=image)
Beispiel #3
0
def main():
    if 'username' not in session:
        return redirect('/login')
    nm = NewsModel(db.get_connection())
    nm.init_table()
    um = UsersModel(db.get_connection())
    um.init_table()
    # nm.delete_all()
    if request.method == "POST":
        content = request.form["comment"]
        # content = request.files["uploadingfiles"]
        avatar = um.get_avatar(session['username'])
        print(avatar)
        nm.insert(str(time.asctime(time.localtime(time.time()))), content,
                  session['username'], avatar)
        for i in nm.get_all():
            check_if_avatar_exists(i)
        return redirect("/main")
    else:
        print(nm.get_all())
        return render_template('home.html',
                               title='Добавление новости',
                               username=session['username'],
                               news=nm.get_all())