collector.py 3.4 KB

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