Guest User

Untitled

a guest
Dec 15th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. @staticmethod
  2. def find(collection, query):
  3. return Database.DATABASE[collection].find(query)
  4.  
  5. @classmethod
  6. def all(cls):
  7. return [cls(**elem) for elem in Database.find(ItemConstants.COLLECTION, {})]
  8.  
  9. @classmethod
  10. def get_by_parameters(cls, name, category, url, size):
  11. return [cls(**elem) for elem in Database.find(ItemConstants.COLLECTION,
  12. {"name": name, "category": category, "url": url,
  13. "size": size}).sort('time', pymongo.DESCENDING).limit(1)][0]
  14.  
  15. @staticmethod
  16. def find_min(collection, query, column):
  17. Database.DATABASE[collection].find(query).sort({column: pymongo.ASCENDING}).limit(1)
  18.  
  19. @classmethod
  20. def get_by_parameters(cls, name, category, url, size):
  21. return cls(**Database.find_min(ItemConstants.COLLECTION,
  22. {"name": name, "category": category, "url": url,
  23. "size": size}, 'time'))
Add Comment
Please, Sign In to add comment