class UserWrapper object _user_model_cache None def _get_model self if

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
class UserWrapper(object):
_user_model_cache = None
def _get_model(self):
if self._user_model_cache is None:
from django.conf import settings
if not getattr(settings, 'AUTH_USER_MODEL', False):
self._user_model_cache = BaseUser
else:
try:
app_label, model_name = settings.AUTH_USER_MODEL.split('.')
self._user_model_cache = models.get_model(app_label, model_name)
except (ImportError):
# TODO: Error logging
raise Exception("Big badaboom")
return self._user_model_cache
def __getattr__(self, name):
return getattr(self._get_model(), name)
def __call__(self, *args, **kwargs):
return self._get_model(*args, **kwargs)
User = UserWrapper()