collector.py 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. ])
  30. return return_list
  31. def check_listing():
  32. # returns list of art available to sell
  33. owned_art = Art.query.filter_by(owner = current_user.id).all()
  34. listed_art = List.query.filter_by(seller = current_user.id).all()
  35. available_art = list()
  36. # to remove art that is already listed
  37. for oa in owned_art:
  38. for la in listed_art:
  39. if oa.filehash != la.filehash:
  40. available_art.append(oa)
  41. if not listed_art:
  42. available_art.append(oa)
  43. return available_art
  44. def check_art_listing(filehash):
  45. # checks List table if art is there
  46. # if not, block redirection to detailed page.
  47. owned_art = Art.query.filter_by(owner = current_user.id).all()
  48. listed_art = List.query.filter_by(seller = current_user.id).all()
  49. for oa in owned_art:
  50. for la in listed_art:
  51. if oa.filehash == la.filehash:
  52. return True
  53. else:
  54. return False
  55. if not listed_art:
  56. return False
  57. def find_user_obj(user_id):
  58. user = User.query.filter_by(id = user_id).first()
  59. return user
  60. def item_bid_hist(filehash):
  61. bids = Bids.query.filter_by(filehash = filehash).order_by(desc(Bids.id)).all()
  62. return bids
  63. def user_bid_hist(user_id):
  64. bids = Bids.query.filter_by(buyer = user_id).order_by(desc(Bids.id)).all()
  65. art = Art.query.all()
  66. return_list = list()
  67. for bid in bids:
  68. for a in art:
  69. if bid.filehash == a.filehash:
  70. return_list.append([
  71. a.name,
  72. bid.bid_date,
  73. bid.bid_price
  74. ])
  75. return return_list
  76. def get_art_obj(filehash):
  77. art = Art.query.filter_by(filehash = filehash).first()
  78. return art