collector.py 3.0 KB

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