collector.py 3.7 KB

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