Advertisement
Guest User

Untitled

a guest
Jul 31st, 2015
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1.  
  2. class LessonCheckMixin(object):
  3. def __init__(self):
  4. # List of method names on mixin
  5. #
  6. self._LESSON_CHECK_METHODS = ['expected_failure', 'companies_check']
  7. def can_see_lessons(self, *args, **kwargs):
  8. """
  9. """
  10. for AUTHORIZATION_CHECK in self._LESSON_CHECK_METHODS:
  11. # Go thru all possible methods
  12. # If any return True success, else return False
  13. try:
  14. getattr(self, AUTHORIZATION_CHECK)()
  15. return True
  16. except:
  17. pass
  18. return False
  19. def companies_check(self, *args, **kwargs):
  20. """
  21. Some check to go see if a user is in a company or something
  22. """
  23. company = 'company' in kwargs
  24. return True
  25. def expected_failure():
  26. """
  27. Simulated failure, would be something like a UserLesson
  28. """
  29. raise
  30.  
  31.  
  32. class PermissionsMixin(LessonCheckMixin):
  33. """
  34. Not a million percent sure on this extra collating
  35.  
  36. Feels ugly to have User inherit directly from a bunch of xCheckMixins
  37. but also having an empty object feesl a bit gross
  38. """
  39. pass
  40.  
  41. class User(PermissionsMixin):
  42. """
  43. """
  44. username = '123'
  45.  
  46. user = User()
  47. user.companies_check(1, b=2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement