Last active
August 29, 2015 14:24
-
-
Save bxh-io/780ddd1c00c6544bc47a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LessonCheckMixin(object): | |
def __init__(self): | |
# List of method names on mixin | |
# | |
self._LESSON_CHECK_METHODS = ['expected_failure', 'companies_check'] | |
def can_see_lessons(self, *args, **kwargs): | |
""" | |
""" | |
for AUTHORIZATION_CHECK in self._LESSON_CHECK_METHODS: | |
# Go thru all possible methods | |
# If any return True success, else return False | |
try: | |
getattr(self, AUTHORIZATION_CHECK)() | |
return True | |
except: | |
pass | |
return False | |
def companies_check(self, *args, **kwargs): | |
""" | |
Some check to go see if a user is in a company or something | |
""" | |
company = 'company' in kwargs | |
return True | |
def expected_failure(): | |
""" | |
Simulated failure, would be something like a UserLesson | |
""" | |
raise | |
class PermissionsMixin(LessonCheckMixin): | |
""" | |
Not a million percent sure on this extra collating | |
Feels ugly to have User inherit directly from a bunch of xCheckMixins | |
but also having an empty object feesl a bit gross | |
""" | |
pass | |
class User(PermissionsMixin): | |
""" | |
""" | |
username = '123' | |
user = User() | |
user.companies_check(1, b=2) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment