# Collects data the retarded way from flask_login import current_user from sqlalchemy import desc from app.models import User, Art, List, Bids def join_art_list_table(): listings = List.query.all() art = Art.query.all() user_list = User.query.all() return_list = list() # Creates a new list for art details # This is retarded. I know. for l in listings: for a in art: if l.filehash == a.filehash: for u in user_list: if a.creator == u.id: return_list.append([ a.name, # [0] name of art a.description, # [1] description of art a.owner, # [2] current owner id u.username, # [3] creator's username u.profile_image, # [4] creator's profilepic a.dname, # [5] designated db name, also path filename l.seller, # [6] current seller id l.min_price, # [7] minimum bid price l.out_price, # [8] minimum buyout price l.timeout, # [9] closing bidding date l.list_date, # [10] listing date l.filehash, # [11] listings/art filehash l.cur_bid # [12] listing's current bid ]) return return_list def check_listing(): # returns list of art available to sell owned_art = Art.query.filter_by(owner = current_user.id).all() listed_art = List.query.filter_by(seller = current_user.id).all() available_art = list() # to remove art that is already listed for art in owned_art: if not listed_art: available_art.append(art) # if none of the list of objects' filehash matches this filehash if not any(la.filehash == art.filehash for la in listed_art): available_art.append(art) return available_art def check_art_listing(filehash): # checks List table if art is there # if not, block redirection to detailed page. owned_art = Art.query.filter_by(owner = current_user.id).all() listed_art = List.query.filter_by(seller = current_user.id).all() for la in listed_art: if filehash == la.filehash: return True return False def find_user_obj(user_id): user = User.query.filter_by(id = user_id).first() return user def item_bid_hist(filehash): bids = Bids.query.filter_by(filehash = filehash).order_by(desc(Bids.id)).all() return bids def user_bid_hist(user_id): bids = Bids.query.filter_by(buyer = user_id).order_by(desc(Bids.id)).all() art = Art.query.all() return_list = list() for bid in bids: for a in art: if bid.filehash == a.filehash: return_list.append([ a.name, bid.bid_date, bid.bid_price ]) return return_list def get_art_obj(filehash): art = Art.query.filter_by(filehash = filehash).first() return art