Ejemplo n.º 1
0
def create_user(login_session):
    """Uses login_session to add user to database."""

    new_user = User(name    =login_session['username'],
                    email   =login_session['email'],
                    picture =login_session['picture'])
    session.add(new_user)
    session.commit()

    user = session.query(User).filter_by(email=login_session['email']).one()
    return user.id
Ejemplo n.º 2
0
def commit_changes(item, crud_function='add'):
    """Commit CRUD changes with proper error catching."""

    try:
        if crud_function == 'add':
            session.add(item)
        else:
            session.delete(item)
        session.commit()
        return True
    except IntegrityError as e:
        session.rollback()
        flash("An error occurred while trying to %s" % crud_function)
        return None