collector.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 oa in owned_art:
  51. for la in listed_art:
  52. if oa.filehash == la.filehash:
  53. return True
  54. else:
  55. return False
  56. if not listed_art:
  57. return False
  58. def find_user_obj(user_id):
  59. user = User.query.filter_by(id = user_id).first()
  60. return user
  61. def item_bid_hist(filehash):
  62. bids = Bids.query.filter_by(filehash = filehash).order_by(desc(Bids.id)).all()
  63. return bids
  64. def user_bid_hist(user_id):
  65. bids = Bids.query.filter_by(buyer = user_id).order_by(desc(Bids.id)).all()
  66. art = Art.query.all()
  67. return_list = list()
  68. for bid in bids:
  69. for a in art:
  70. if bid.filehash == a.filehash:
  71. return_list.append([
  72. a.name,
  73. bid.bid_date,
  74. bid.bid_price
  75. ])
  76. return return_list
  77. def get_art_obj(filehash):
  78. art = Art.query.filter_by(filehash = filehash).first()
  79. return art