Skip to content

Instantly share code, notes, and snippets.

@bxh-io
Last active August 29, 2015 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bxh-io/780ddd1c00c6544bc47a to your computer and use it in GitHub Desktop.
Save bxh-io/780ddd1c00c6544bc47a to your computer and use it in GitHub Desktop.
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