collector.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # Collects data the retarded way
  2. from flask_login import current_user
  3. from app.models import User, Art, List
  4. def market_listing():
  5. listings = List.query.all()
  6. art = Art.query.all()
  7. user_list = User.query.all()
  8. return_list = list()
  9. # Creates a new list for art details
  10. for l in listings:
  11. for a in art:
  12. if l.filehash == a.filehash:
  13. for u in user_list:
  14. if a.creator == u.id:
  15. return_list.append([
  16. a.name, # [0] name of art
  17. a.description, # [1] description of art
  18. a.owner, # [2] current owner id
  19. u.username, # [3] creator's username
  20. u.profile_image, # [4] creator's profilepic
  21. a.dname, # [5] designated db name, also path filename
  22. l.seller, # [6] current seller id
  23. l.min_price, # [7] minimum bid price
  24. l.out_price, # [8] minimum buyout price
  25. l.timeout, # [9] closing bidding date
  26. l.list_date, # [10] listing date
  27. l.filehash # [11] listings/art filehash
  28. ])
  29. return return_list
  30. def check_listing():
  31. # returns list of art available to sell
  32. owned_art = Art.query.filter_by(owner=current_user.id).all()
  33. listed_art = List.query.filter_by(seller=current_user.id).all()
  34. available_art = list()
  35. # to remove art that is already listed
  36. for oa in owned_art:
  37. for la in listed_art:
  38. if oa.filehash != la.filehash:
  39. available_art.append(oa)
  40. return available_art
  41. def find_user_obj(user_id):
  42. user = User.query.filter_by(id=user_id).first()
  43. return user