def test_get_user_listings(self): listings = db.get_user_listings(1) self.assertEqual( len(listings), 1, "Get User Listings Day 1 - Unexpected number of listings returned for user with id 1." ) listings = db.get_user_listings(4) self.assertEqual( len(listings), 2, "Get User Listings Day 1 - Unexpected number of listings returned for user with id 4." )
def account(): if 'user_id' in session: user = db.get_one_user(session['user_id']) name = '{} {}'.format(user['first_name'].capitalize(), user['last_name'].capitalize()) address = helper_functions.address_string(session['user_id']) map_url = helper_functions.address_url(address[1]) listings = db.get_user_listings(session['user_id']) orders = db.get_user_orders(session['user_id']) for listing in listings: listing['price_per_unit'] = '${:,.2f}'.format( listing['price_per_unit']) for order in orders: order['total_cost'] = '${:,.2f}'.format(order['total_cost']) order['time_placed'] = 'Purchased on {}'.format( order['time_placed'].strftime('%B %e')) tab_choice = request.args.get('type') return render_template('account-main.html', user=user, name=name, location_address=address[0], location_link=map_url, tab_choice=tab_choice, listings=listings, orders=orders) else: return redirect(url_for('login'))
def profile(user): current_user = session.get('remember') session['search-feed'] = None if request.method == 'POST': update_profile_pic(request, user) origin_items, listingPhotos = db.get_user_listings(user) sorted_items = sort_items(session['location'], origin_items) return render_template('profile.html', items=sorted_items[0], image="/static/images/uploaded/" + str(db.get_profile_pic(user)[0]) + ".jpg", item_photos=listingPhotos, current_user=current_user)
def user_profile(user_id): rel_link = helper_functions.relative_link(request.path, request.referrer) user = db.get_one_user(user_id) listings = db.get_user_listings(user_id) address = helper_functions.address_string(user_id) map_url = helper_functions.address_url(address[1]) name = '{} {}'.format(user['first_name'].capitalize(), user['last_name'].capitalize()) return render_template('profile.html', rel_link=rel_link, name=name, user=user, listings=listings, location_address=address[0], location_link=map_url)
def test_get_user_listings(self): listings = db.get_user_listings(4) self.assertEqual( len(listings), 0, "Get User Listings Day 0 - Returned listings for non-existent user." )