Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. class UserCompany(db.Document, TransitionalDatabaseMixin):
  2. '''
  3. A company that our users belong to. Not to be confused with
  4. companies that are offering positions.
  5. '''
  6. # Classic getter with no filtering.
  7. @classmethod
  8. def get_by_ats_id(cls, ats_id):
  9. return cls.objects(ats_id=ats_id).first()
  10.  
  11. # Provide a getter that supports filtering.
  12. # The naming convention implies the getter filters.
  13. # The downside here is that we need to name a filtered getter for every
  14. # getter we define.
  15. @classmethod
  16. def get_by_ats_id_with_limits(cls, ats_id, *limits):
  17. return cls.objects(ats_id=ats_id).only(*limits)
  18.  
  19. # An alternate solution is to keep our default named getter and have an
  20. # optional list of filters that maybe be defined. The caller may now use
  21. # the same getter when they want all fields or just a subset.
  22. @classmethod
  23. def get_by_ats_id(cls, ats_id, limits=[]):
  24. return cls.objects(ats_id=ats_id).only(*limits)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement