コード例 #1
0
def addtowishlist(adId):
    cookie_session_id = request.cookies.get('session_id')
    user_id, user_name = sessionutils.get_customer_details_from_session_id(
        cookie_session_id)
    count = wishlist.select().where(wishlist.adId == adId).count()
    #print("count", count)

    # checks if wishlist database is empty
    # checks if item is already added to wishlist to avoid duplication
    if count > 0:
        list = getWishlistAttributes(adId)
        for entry in list:
            #print("for loop in wishlist ")
            #print("entry.userid",entry.userId, "entry.adID",entry.adId, "my user id is",user_id)
            if entry.userId == user_id:
                #print("entry.userid == user-id")
                return redirect('/')


# adds item to wishlist
    else:
        _adId = adId
        _userId = user_id
        wishlist.create(adId=_adId, userId=_userId)
        info = "Success! The book was added to you wishlist. Go to your account page to see it."
        flash(info)
        return redirect('/')
コード例 #2
0
def leave_feedback(feedback_ad_id):
    """ @summary A function to render and handle a form for leaving feedback for another user
        @param feedback_ad_id - The ad ID number for which feedback is to be left for
    Server-side method for the UI to interact with the MySQL database
    """
    cookie_session_id = request.cookies.get('session_id')
    user_id, user_name = sessionutils.get_customer_details_from_session_id(cookie_session_id)
    ad = transactions.get(transactions.adId == feedback_ad_id)

    if request.method == 'POST':
        if feedback_ad_id is not None:
    
            if user_id > -1:
                #TODO get from UI
                print("Get input from UI")
                giver=user_id
                if ad.sellerId==user_id:
                    receiver= ad.buyerid
                else:
                    receiver=ad.sellerId
                #TODO logic to make this work for buyer and seller
                if ad.buyerid==user_id:
                    feedbackreceivertype="s"
                else:
                    feedbackreceivertype="b"
                print("receeiver type is ",feedbackreceivertype)
                feedbackInput = request.form['inputFeedback']
                ratingInput = request.form['inputRating']
                feedback.create(giverId=giver , receiverId=receiver,
                                 adId=feedback_ad_id, feedback=feedbackInput, rating=ratingInput, ad=ad, userId=user_id)
    
            else:
                response = make_response(redirect("/login", code=403))
                error ='Please login to leave feedback'
                response.set_cookie('message_text', error, domain='kaizen.localhost')
                return response
        else:
            response = make_response(redirect("/account", code=403))
            error = 'Please select and ad to leave feedback'
            response.set_cookie('message_text', error, domain='kaizen.localhost')
            return response
        user = users.get(users.id == ad.sellerId)
    
        return redirect("/account/my-account")
    else:
        user = users.get(users.id==ad.sellerId)
        if ad.buyerid == user_id:
            feedbackreceivertype = "s"
        else:
            feedbackreceivertype = "b"
        print("feedbackreceivertype is:",feedbackreceivertype)
    
    
        return render_template('feedback.html', name=user_name, feedbackid=feedback_ad_id, receiver=user.firstName,
                                book=get_feedback_book_title(feedback_ad_id),receiverType=feedbackreceivertype,
                                blah=calculate_rating(ad.sellerId))
コード例 #3
0
def sell_book(adId):
    ad = adListing.get(adListing.id == adId)
    print("flag before toggle : ", ad.activeFlag)
    variable = adListing.update(activeFlag=0).where(adListing.id == adId)
    variable.execute()
    transactions.create(adId=ad.id, sellerId=ad.sellerId, buyerid=ad.buyerId)
    print("changed flag to false : ",ad.activeFlag)
    cookie_session_id = request.cookies.get('session_id')
    user_id, user_name = sessionutils.get_customer_details_from_session_id(cookie_session_id)
    return redirect("/account/my-account")
コード例 #4
0
def create_listing():
    """"" @summary A function to render and handle a for creating an ad
    Page for a form to be able to create a listing
    """
    cookie_session_id = request.cookies.get('session_id')
    user_id, user_name = sessionutils.get_customer_details_from_session_id(cookie_session_id)
    if request.method == 'POST':
        uploadFileFlag = 0
        filename = secure_filename("default.jpg")
        # Remove this print statement if running flask in prod
        print("DEBUG: Posting form")
        # ### code for the ad listing form ###
        # Get the form inputs
        # Remove this print statement if running flask in prod
        # print(request.form)
        _title = request.form['inputTitle']
        _desc = request.form['inputDesc']
        _name = "NULL"

        try:
            session.select(session.customer_id).where(session.session_id == request.cookies.get['session_id']).first()
        except:
            print("SQL error getting user session")
        try:
            _name = users.select(users.name).join(session).where(session.customer_id == users.id).first()
        except:
            print("SQL error getting user's name from session")
        _cond = request.form['inputCond']
        _isbn = request.form['inputISBN13']
        _author = request.form['inputAuthor']
        _price = request.form['inputPrice']
        _year = request.form['inputYear']
        _pub = request.form['inputPublisher']
        _edi = request.form['inputEdi']

        try:
            file = request.files['imgFile']
            #print(file)
            if file.filename != '':
                filename = secure_filename(file.filename)
                #print(filename)
                uploadFileFlag = 1
        except:
            print("Looks like no file attached")

        adListing.create(title=_title.strip(), sellerId=user_id, price=_price, imageLocation=filename, description=_desc,
                         condition=_cond, _price=_price, sellerName=_name, author=_author, year=_year,
                         publisher=_pub, edition=_edi, isbn=_isbn, status="active")

        if uploadFileFlag == 1:
            print("attempting to upload image")
            upload_from_another_form(file)
        return redirect('/')
    else:
        return render_template('newad.html', name=user_name)
コード例 #5
0
def show_account():
    """ @summary A function to render the my account page
    """
    cookie_session_id = request.cookies.get('session_id')
    user_id, user_name = sessionutils.get_customer_details_from_session_id(cookie_session_id)


    # status =
    return render_template("/show-account.html", soldbooklistings=get_current_sold_books(user_id),
                           currentbooks=get_current_books_for_sale(user_id), feedbacklist=get_feedback_from_userid(user_id),
                           userid=user_id, name=user_name, adlist=getAdlistings(), boughtlist=get_bought_books(user_id), wishlist=get_wishlist_books(user_id))
コード例 #6
0
def main():
    """ @summary A function to define the main application route
    """
    if request.method == 'POST':
        return redirect('/')
    cookie_session_id = request.cookies.get('session_id')
    user_id, user_name = sessionutils.get_customer_details_from_session_id(
        cookie_session_id)

    return render_template('home.html',
                           listings=getAdlistingsTop12(),
                           userid=user_id,
                           name=user_name)
コード例 #7
0
def commitment(adId):
    """ @summary A function that renders the template for a committed buyer
    """
    cookie_session_id = request.cookies.get('session_id')
    user_id, user_name = sessionutils.get_customer_details_from_session_id(
        cookie_session_id)
    ad = adListing.get(adListing.id == adId)
    seller = users.get(users.id == ad.sellerId)
    set_buyer_id_when_committing(adId, user_id)
    return render_template('commit.html',
                           listings=getAdlistings(),
                           userid=user_id,
                           name=user_name,
                           ad=ad,
                           seller=seller)
コード例 #8
0
def showItem(adId):
    """ @summary A function that renders a template for viewing the individual ad listing
        This shows a page with the individual product item information
    """
    cookie_session_id = request.cookies.get('session_id')
    user_id, user_name = sessionutils.get_customer_details_from_session_id(
        cookie_session_id)
    ad = adListing.get(adListing.id == adId)
    sellerid = users.get(users.id == ad.sellerId)
    print(ad.title)
    return render_template("product-page.html",
                           ad=ad,
                           userid=user_id,
                           name=user_name,
                           sellerid=sellerid,
                           rating=calculate_rating(sellerid.id))
コード例 #9
0
def about():
    cookie_session_id = request.cookies.get('session_id')
    user_id, user_name = sessionutils.get_customer_details_from_session_id(
        cookie_session_id)

    return render_template('about.html', userid=user_id, name=user_name)