Exemplo n.º 1
0
def show_welcome_page():
    """user welcome page"""

    user_id = session['user_id']
    user = crud.get_user_by_user_id(user_id)

    return render_template("welcome_page.html", user=user)
Exemplo n.º 2
0
def save_added_transaction():
    """Add A transactions and send it to db, user can view it after redirected back to the overview page."""

    if session.get('user_id'):
        submit_add_transaction_form = request.form.get(
            "submit_add_transaction_form")

        if submit_add_transaction_form == 'Submit':
            account_id = request.form.get("selected_account")
            merchant_name = request.form.get('merchant_name')
            amount = request.form.get('amount')
            date = request.form.get('transaction_date')
            user = crud.get_user_by_user_id(
                session['user_id'])  #gets user by session user_id

            # If new merchant_name, add the new merchant_name to merchant table
            crud.create_merchant_name(merchant_name, user)
            # Then we can created a transaction using a new merchant_name.
            crud.create_transaction(amount, date, merchant_name, user,
                                    account_id)
            # After transaction is added, now we can update associated account balance through acccount_id
            crud.get_account_by_account_id(account_id, amount)

            flash('New transaction Has Been added!')
            return redirect('/overview')

        else:
            flash('Sorry, something went wrong. Please try again.')
            return redirect('/add_transaction')
    else:
        flash('Please login to proceed to this page.')
        return redirect('/login')
Exemplo n.º 3
0
def view_current_user_profile():
    """Display a user profile."""

    user_id = session['current_user']
    user = crud.get_user_by_user_id(user_id)

    movies_watched_count = crud.get_movies_watched_count(
        user_id)  #TODO: make func in crud file
    reviews_written_count = crud.get_reviews_written_count(
        user_id)  #TODO: make func in crud file
    ratings_given_count = crud.get_ratings_given_count(
        user_id)  #TODO: make func in crud file

    seenlist = crud.return_seenlist(user_id)  #TODO: make func in crud file
    watchlist = crud.return_watchlist(user_id)  #TODO: make func in crud file

    reviews = crud.return_reviews_by_user_id(
        user_id)  #TODO: make func in crud file

    return render_template('user_profile.html',
                           user=user,
                           movies_watched_count=movies_watched_count,
                           reviews_written_count=reviews_written_count,
                           ratings_given_count=ratings_given_count,
                           seenlist=seenlist,
                           watchlist=watchlist,
                           reviews=reviews)
Exemplo n.º 4
0
def save_created_budget():
    """Create A Budget and send to db, user can view it after redirected back to budgets page."""

    if session.get('user_id'):
        submit_budget_form = request.form.get("submit_budget_form")

        if submit_budget_form == 'Submit':
            merchant_name = request.form.get('selected_merchant')
            spend_limit = request.form.get('amount')
            start_date = request.form.get('start_date')
            end_date = request.form.get('end_date')
            status = "active for storage"
            print(end_date)
            print(date.today())
            #gets user by session user_id
            user = crud.get_user_by_user_id(session['user_id'])

            budget_response = crud.create_budget(status, spend_limit,
                                                 start_date, end_date, user,
                                                 merchant_name)
            if budget_response == "budget-created":
                flash('New Budget Has Been Created!')
                return redirect('/budgets')

            elif budget_response == "budget-exsists":
                flash(
                    "An active budget already exsits for this merchant, you can view it below in the active budgets' table!"
                )
                return redirect('/budgets')
    else:
        flash('Please login to proceed to this page.')
        return redirect('/login')
Exemplo n.º 5
0
def save_added_bank_account():
    """Add a bank account and send it to db, user can view it after being redirected back to the overview page."""

    if session.get('user_id'):
        submit_add_account_form = request.form.get("submit_add_account_form")

        if submit_add_account_form == 'Submit':
            account_id = request.form.get("account_name")
            name = request.form.get("account_name")
            available_balance = request.form.get("available_balance")
            type = "depository"
            user = crud.get_user_by_user_id(
                session['user_id'])  #gets user by session user_id

            crud.create_account(account_id, available_balance, type, name,
                                user)

            flash('New bank account Has Been added!')
            return redirect('/overview')

        else:
            flash('Sorry, something went wrong. Please try again.')
            return redirect('/add_account')
    else:
        flash('Please login to proceed to this page.')
        return redirect('/login')
Exemplo n.º 6
0
def get_create_budget():
    """View create budget form."""

    if session.get('user_id'):
        user = crud.get_user_by_user_id(session['user_id'])
        return render_template('create_budget.html',
                               merchants=user.merchants)  # user merchant table
    else:
        flash('Please login to proceed to this page.')
        return redirect('/login')
Exemplo n.º 7
0
def get_add_transaction():
    """View add transaction form."""

    if session.get('user_id'):
        user = crud.get_user_by_user_id(session['user_id'])
        return render_template('add_transactions.html',
                               accounts=user.accounts,
                               merchants=user.merchants)
    else:
        flash('Please login to proceed to this page.')
        return redirect('/login')
Exemplo n.º 8
0
def overview_data():
    """View transactions and account balance information"""

    if session.get('user_id'):
        user = crud.get_user_by_user_id(session['user_id'])
        return render_template('overview.html',
                               transactions=user.transactions,
                               accounts=user.accounts)
    else:
        flash('Please login to proceed to this page.')
        return redirect('/login')
Exemplo n.º 9
0
def show_user_profile():
    """Render profile page of user that is logged in."""

    if session.get('username', 0) == 0:
        return redirect('/signin')

    user = session['username']
    email = session['email']
    account = crud.get_user_by_email(email)
    user_reviews = account.reviews
    user_collections = account.collections
    user_profile_picture = account.profile_picture
    user_bio = account.user_bio
    created_on = account.created_on
    birthday = account.birthday
    website = account.website

    user_friends = []
    user_friendships = account.added_friends
    for friendship in user_friendships:
        user_friend_id = friendship.friend_id
        friend_account = crud.get_user_by_user_id(user_friend_id)
        user_friends.append(friend_account)

    user_collections_pods = {}

    session['collections'] = {}

    for collection in user_collections:

        session['collections'][collection.collection_id] = collection.name

        collection_pods = []

        for pod in collection.collection_podcasts:
            pod_object = crud.get_podcast_by_id(pod.podcast_id)
            collection_pods.append(pod_object)

        user_collections_pods[collection.name] = collection_pods

    return render_template('user_profile.html',
                           user=user,
                           email=email,
                           reviews=user_reviews,
                           birthday=birthday,
                           website=website,
                           profile_picture=user_profile_picture,
                           user_bio=user_bio,
                           friends=user_friends,
                           created_on=created_on,
                           collections=user_collections,
                           collections_details=user_collections_pods)
Exemplo n.º 10
0
def show_other_user_profile(username):
    """Show the user profile of other registered users"""

    account = crud.get_user_by_username(username)
    reviews = account.reviews
    collections = account.collections
    profile_picture = account.profile_picture
    user_bio = account.user_bio
    created_on = account.created_on
    user_id = account.user_id
    birthday = account.birthday
    website = account.website

    user_friends = []
    user_friendships = account.added_friends
    for friendship in user_friendships:
        user_friend_id = friendship.friend_id
        friend_account = crud.get_user_by_user_id(user_friend_id)
        user_friends.append(friend_account)

    collection_names = {}
    collections_pods = {}

    for collection in collections:

        collection_names[collection.collection_id] = collection.name

        collection_pods = []

        for pod in collection.collection_podcasts:
            pod_object = crud.get_podcast_by_id(pod.podcast_id)
            collection_pods.append(pod_object)

        collections_pods[collection.name] = collection_pods

    return render_template('other_users.html',
                           user=username,
                           reviews=reviews,
                           profile_picture=profile_picture,
                           birthday=birthday,
                           website=website,
                           user_bio=user_bio,
                           friends=user_friends,
                           created_on=created_on,
                           collections=collections,
                           collections_details=collections_pods,
                           profile_user_id=user_id)
Exemplo n.º 11
0
def profile():
    """display user's profile page"""

    current_user_id = session.get('current_user', None)

    if current_user_id:

        current_user = crud.get_user_by_user_id(current_user_id)
        total_mileage = crud.get_total_mileage(current_user_id)
        total_runs = crud.get_total_number_of_runs(current_user_id)
        avg_pace = crud.get_avg_run_time(current_user_id)

        return render_template('profile.html',
                               current_user=current_user,
                               total_mileage=total_mileage,
                               total_runs=total_runs,
                               avg_pace=avg_pace)
Exemplo n.º 12
0
def get_budgets():
    """View budgets page."""

    if session.get('user_id'):
        user = crud.get_user_by_user_id(session['user_id'])
        date_now = datetime.now()
        count_alive = crud.get_garden_alive_count(user)
        count_dead = crud.get_garden_dead_count(user)

        return render_template('budgets.html',
                               user_name=user.user_name,
                               budgets=user.budgets,
                               date_now=date_now,
                               count_alive=count_alive,
                               count_dead=count_dead)
    else:
        flash('Please login to proceed to this page.')
        return redirect('/login')
Exemplo n.º 13
0
def show_user(user_id):
    user = crud.get_user_by_user_id(user_id)
    return render_template('user_details.html', user=user)
Exemplo n.º 14
0
 def test_get_user_by_user_id(self):
     user_id = 1
     user = crud.get_user_by_user_id(user_id)
     self.assertEqual(user.user_id, user_id)