def sellHand_show(fc): #check if FC exist in DB result = Seller.select().where(Seller.choice == "Cabin", Seller.flightcode == fc, Seller.sold == False) if result: if current_user.is_authenticated: seller_list = Seller.select().where( Seller.choice == "Cabin", Seller.flightcode == fc, Seller.sold == False, Seller.buyer_id.is_null(True), Seller.sold.is_null(False) & (Seller.seller_id != current_user.id)) ranNum = random.randint(0, seller_list.count()) ranNum -= 1 if ranNum < 0: ranNum = 0 else: ranNum = ranNum return render_template('sellHand/sellHand_market.html', seller=seller_list[ranNum], result=result[ranNum].id) else: return render_template('homepage2.html', noflight="No Available Sellers")
def sellHand_show(fc): #check if FC exist in DB result = Seller.select().where(Seller.choice == "Cabin", Seller.flightcode == fc) if result: seller_list = Seller.select().where(Seller.choice == "Cabin", Seller.flightcode == fc, Seller.sold == False, Seller.buyer_id.is_null(True), Seller.sold.is_null(False)) ranNum = random.randint(0, seller_list.count()) ranNum -= 1 if ranNum < 0: ranNum = 0 else: ranNum = ranNum return render_template('sellHand/sellHand_market.html', seller=seller_list[ranNum]) else: return render_template('sellHand/sellHand.html')
def availability(): flightcode = request.form.get('flightcode') time = request.form.get('time') date = request.form.get('date') now = str(datetime.datetime.now()) if current_user.is_authenticated: available = Seller.select().where( (Seller.flightcode == flightcode) & (Seller.departure_date == date) & (Seller.departure_time == time) & (Seller.sold == False) & (Seller.choice == 'Luggage') & (Seller.seller_id != current_user.id)) d = re.search('\d+-\d+-\d+', now) if d: date = d.group(0) t = re.search('\d+:\d+:\d+', now) if t: time = t.group(0) list_of_sellers = Seller.select().where( (Seller.departure_date >= date) & (Seller.sold != True) & (Seller.choice == 'Luggage') & (Seller.seller_id != current_user.id)) else: available = Seller.select().where((Seller.flightcode == flightcode) & (Seller.departure_date == date) & (Seller.departure_time == time) & (Seller.sold == False) & (Seller.choice == 'Luggage')) d = re.search('\d+-\d+-\d+', now) if d: date = d.group(0) t = re.search('\d+:\d+:\d+', now) if t: time = t.group(0) list_of_sellers = Seller.select().where((Seller.departure_date >= date) & (Seller.sold != True) & (Seller.choice == 'Luggage')) return render_template('seller/marketplace.html', available=available, list_of_sellers=list_of_sellers)
def userprofile(id): int_id = int(id) user = User.get(User.id == int_id) username = user.username ic_name = user.ic_name handphone = user.handphone profilepic = user.profilepic purchase = Seller.select().where(Seller.buyer_id == int_id) return render_template('profile/userprofile.html', int_id=int_id, username=username, ic_name=ic_name, handphone=handphone, profilepic=profilepic, purchase=purchase)
def profile(): pic = User.get(User.id == current_user.id).profilepic_url purchase = Seller.select().where(Seller.buyer_id == current_user.id) rated = Rate.select().where(Rate.rater_id == current_user.id) rated_ids = [r.user_being_rated_id.id for r in rated] everyone = User.select() # score = [] # for r in rated : # sum_score = Rate.select(fn.SUM('score')).where(Rate.user_being_rated_id == r.user_being_rated_id) # total_records = raters.count() # final_rating = sum_score/total_records # score.append(final_rating) return render_template('profile/profile.html', pic=pic, purchase=purchase, rated_ids=rated_ids)