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")
def get_wishlist_books(userid):
        wishlistBooks = []
        count = adListing.select().where(adListing.buyerId == userid)
        if count > 0:
            wishlists = wishlist.select().where(wishlist.userId == userid)
            for book in wishlists:
                item = adListing.get(adListing.id == book.adId)
                wishlistBooks.append(item)

            return wishlistBooks
        else:
            return "You have not saved any books to your wishlist yet"
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)
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))
def getAdListingStatusFromAdId(adId):
    adList = adListing.get(adListing.id == adId)
    return adList.status
def get_feedback_book_title(adId):
    ad = adListing.get(adListing.id == adId)
    return ad.title
def get_feedback_book_title(adId):
    """ @summary A function get the feedback recipient type
        @param adId - The ID number of the ad listing
    """
    ad = adListing.get(adListing.id == adId)
    return ad.title