Example #1
0
def page_of_users():
    # email = input("Enter your email: ")

    session = Database.create_session()
    session.expire_on_commit = False
    # with Database.create_session() as session:

    users = session.query(User). \
        filter(User.id != None).\
        order_by(User.registered.desc())

    page_size = 10
    current_page = 3

    results = users[page_size * current_page:page_size * (current_page+1)]
    # results = users[1:5]

    for u in results:
        print(u.name)
Example #2
0
def add_data():
    session = Database.create_session()

    num = session.query(User).count()
    if num:
        print("data loaded, skipping")
        return

    u = User(
        name='Michael',
        email='*****@*****.**',
        pw='a'
    )
    session.add(u)

    u = User(
        name='Ted',
        email='*****@*****.**',
        pw='9837598w75983749857349857398745'
    )
    session.add(u)
    session.commit()
Example #3
0
def find_user(email):
    # email = input("Enter your email: ")

    session = Database.create_session()
    session.expire_on_commit = False
    # with Database.create_session() as session:

    user = session.query(User). \
        filter(User.email == email).\
        order_by(User.registered.desc())


    user = user.first()
    if user:
        # print("results: {}".format(user.name))
        user.name = user.name.upper()
        session.commit()
        print("Saved user")
        session.close()
        return user
    else:
        # print("not found!")
        return None