Esempio n. 1
0
def food_info(food_id):
    # Display information about a specific food listing.

    if check_login('Please login to view listing details.') == 'not_logged_in':
        return redirect('/login')
    else:
        # get specific listing from db.
        food_listing = Food.query.get(food_id)
        user = get_user()
        new_messages = get_new_messages(session['user_id'])

        return render_template('food_info.html',
                               food_listing=food_listing,
                               user=user,
                               new_messages=new_messages)
Esempio n. 2
0
def listings():
    # Lists all the food listings, putting the user's friends'
    # listings first.

    if check_login('Please login to view listings.') == 'not_logged_in':
        return redirect('/login')

    else:
        user = get_user()
        new_messages = get_new_messages(session['user_id'])
        user_friends = user.friendships

        if user_friends:
            friend_ids = [friend.friend_id for friend in user_friends]

            # get all their friend's listings
            friends_listings = Food.query.filter_by(active=True
                                                    ).filter(
                                                    Food.user_id.in_(friend_ids)
                                                    ).order_by(
                                                    desc('post_date')
                                                    ).all()

            # get the food ids so they can be filtered out
            friends_food_ids = [food.food_id for food in friends_listings]

            # get all the other active listings
            other_listings = Food.query.filter_by(active=True
                                                  ).filter(~Food.food_id.in_(
                                                   friends_food_ids)
                                                   ).order_by(desc('post_date')
                                                              ).all()

            # combine listings so that the friends listings come first
            foods = friends_listings + other_listings

        else:
            foods = Food.query.filter_by(active=True).order_by(desc
                                                               ('post_date')
                                                               ).all()

        API_KEY = google_api

        return render_template('listings.html',
                               foods=foods,
                               user=user,
                               new_messages=new_messages,
                               API_KEY=API_KEY)
Esempio n. 3
0
def login():
    username = request.form['username']
    password = request.form['password']
    success = helper.check_login(username, password)
    if not success:
        return render_template("sign.html", error='用户名密码错误')

    # create session_id
    session_id = helper.generate_session_id()
    user = databaseq.get_user_by_name(username)
    uid = user[0]
    databaseq.insert_session(session_id, uid)

    resp = redirect(url_for('home'))
    resp.set_cookie('SESSION_ID', session_id)
    return resp
Esempio n. 4
0
def edit_food(food_id):
    # Display information about a specific food listing
    # allow the user to edit listing.

    if check_login('Please login to edit your listings.') == 'not_logged_in':
        return redirect('/login')
    else:
        # show user listing and allow them to make changes.
        user = get_user()
        new_messages = get_new_messages(session['user_id'])
        food_listing = Food.query.get(food_id)

        return render_template('editfood.html',
                               food_listing=food_listing,
                               user=user,
                               new_messages=new_messages)
Esempio n. 5
0
def user_info(food_user_id):
    # Displays a specific user's active listings.

    if check_login("Please login to view\
                   this user's listings.") == 'not_logged_in':
        return redirect('/login')
    else:
        # get specific listing from db.
        user = get_user()
        new_messages = get_new_messages(session['user_id'])
        this_user = User.query.get(food_user_id)
        food_listings = Food.query.filter_by(user_id=food_user_id)

        return render_template('user_info.html',
                               this_user=this_user,
                               food_listings=food_listings,
                               user=user,
                               new_messages=new_messages)
Esempio n. 6
0
def messages():
    # Displays messages for that specific user.

    if check_login("Please login to view your messages.") == 'not_logged_in':
        return redirect('/login')
    else:
        # Get the messages for that particular user.
        user = get_user()
        new_messages = get_new_messages(session['user_id'])

        unread_messages = get_messages(session['user_id'], False)

        read_messages = get_messages(session['user_id'], True)

        all_messages = unread_messages + read_messages

        return render_template('messages.html',
                               all_messages=all_messages,
                               unread_messages=unread_messages,
                               read_messages=read_messages,
                               user=user,
                               new_messages=new_messages)
Esempio n. 7
0
def user_listings():
    # Shows a list of all of that particular user's listings.

    if check_login('Please login to view your listings.') == 'not_logged_in':
        return redirect('/login')
    else:
        # show user's listings.
        user = get_user()
        new_messages = get_new_messages(session['user_id'])
        user_id = session['user_id']
        question = Food.query
        user_listings = question.filter(Food.user_id == user_id,
                                        Food.active == True
                                        ).order_by(desc('post_date')).all()
        old_listings = question.filter(Food.user_id == user_id,
                                       Food.active == False
                                       ).order_by(desc('post_date')).all()

        return render_template('mylistings.html',
                               user_listings=user_listings,
                               old_listings=old_listings,
                               user=user,
                               new_messages=new_messages)
 def test_check_login(self):
     login_return_1 = helper.check_login('bbuild', 'password')
     login_return_2 = helper.check_login('bbuilder', 'hi')
     self.assertEqual(login_return_1, 'True')
     self.assertEqual(login_return_2, 'False')
Esempio n. 9
0
def home():
    # homepage

    if check_login('Please login.') == 'not_logged_in':
        return redirect('/login')

    else:
        user = get_user()
        new_messages = get_new_messages(session['user_id'])
        user_friends = user.friendships

        if user_friends:
            # get this user's friend ids
            friend_ids = [friend.friend_id for friend in user_friends]
            friends_fb_ids = db.session.query(User.user_id,
                                              User.fb_id).filter(
                                              User.user_id.in_(friend_ids)
                                              ).all()

            # get all their friend's listings
            friends_listings = []
            for friend in friend_ids:
                listing = Food.query.filter_by(active=True
                                               ).filter(
                                               Food.user_id == friend
                                               ).order_by(desc('post_date')
                                                          ).first()
                if listing:
                    friends_listings.append(listing)

            # get the food ids so they can be filtered out
            friends_food_ids = [food.food_id for food in friends_listings]

            user_id = session['user_id']

            # get all the other active listings,
            # leaving out friend and user listings
            other_listings = Food.query.filter_by(active=True
                                                  ).filter(
                                                  (~Food.user_id.in_(friend_ids)),
                                                  (~(Food.user_id == user_id))
                                                  ).order_by(desc('post_date')
                                                             ).all()

            # combine listings so that the friends listings come first
            this_users_listings = friends_listings + other_listings
            short_list = this_users_listings[:5]
        else:
            short_list = Food.query.filter_by(active=True
                                              ).order_by(desc('post_date')
                                                         ).limit(5).all()
            friends_fb_ids = None

        current_date = datetime.now()
        current_date = current_date.strftime("%Y-%m-%d")

        return render_template('index.html',
                               user_listings=short_list,
                               current_date=current_date,
                               user=user,
                               new_messages=new_messages,
                               user_friends=user_friends,
                               friends_fb_ids=friends_fb_ids)