collector.py 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. # Collects data the retarded way
  2. from flask_login import current_user
  3. from sqlalchemy import desc
  4. from app.models import User, Art, List, Bids
  5. def join_art_list_table():
  6. listings = List.query.all()
  7. art = Art.query.all()
  8. user_list = User.query.all()
  9. return_list = list()
  10. # Creates a new list for art details
  11. # This is retarded. I know.
  12. for l in listings:
  13. for a in art:
  14. if l.filehash == a.filehash:
  15. for u in user_list:
  16. if a.creator == u.id:
  17. return_list.append([
  18. a.name, # [0] name of art
  19. a.description, # [1] description of art
  20. a.owner, # [2] current owner id
  21. u.username, # [3] creator's username
  22. u.profile_image, # [4] creator's profilepic
  23. a.dname, # [5] designated db name, also path filename
  24. l.seller, # [6] current seller id
  25. l.min_price, # [7] minimum bid price
  26. l.out_price, # [8] minimum buyout price
  27. l.timeout, # [9] closing bidding date
  28. l.list_date, # [10] listing date
  29. l.filehash, # [11] listings/art filehash
  30. l.cur_bid # [12] listing's current bid
  31. ])
  32. return return_list
  33. def check_listing():
  34. # returns list of art available to sell
  35. owned_art = Art.query.filter_by(owner = current_user.id).all()
  36. listed_art = List.query.filter_by(seller = current_user.id).all()
  37. available_art = list()
  38. # to remove art that is already listed
  39. for art in owned_art:
  40. if not listed_art:
  41. available_art.append(art)
  42. # if none of the list of objects' filehash matches this filehash
  43. if not any(la.filehash == art.filehash for la in listed_art):
  44. available_art.append(art)
  45. return available_art
  46. def check_art_listing(filehash):
  47. # checks List table if art is there
  48. # if not, block redirection to detailed page.
  49. owned_art = Art.query.filter_by(owner = current_user.id).all()
  50. listed_art = List.query.filter_by(seller = current_user.id).all()
  51. for la in listed_art:
  52. if filehash == la.filehash:
  53. return True
  54. return False
  55. def find_user_obj(user_id):
  56. user = User.query.filter_by(id = user_id).first()
  57. return user
  58. def item_bid_hist(filehash):
  59. bids = Bids.query.filter_by(filehash = filehash).order_by(desc(Bids.id)).all()
  60. return bids
  61. def user_bid_hist(user_id):
  62. bids = Bids.query.filter_by(buyer = user_id).order_by(desc(Bids.id)).all()
  63. art = Art.query.all()
  64. return_list = list()
  65. for bid in bids:
  66. for a in art:
  67. if bid.filehash == a.filehash:
  68. return_list.append([
  69. a.name,
  70. bid.bid_date,
  71. bid.bid_price
  72. ])
  73. return return_list
  74. def get_art_obj(filehash):
  75. art = Art.query.filter_by(filehash = filehash).first()
  76. return art