Created
March 6, 2012 18:25
-
-
Save michaelhelmick/1987914 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
def get_profile(self): | |
""" | |
Returns site-specific profile for this user. Raises | |
SiteProfileNotAvailable if this site does not allow profiles. | |
""" | |
if not hasattr(self, '_profile_cache'): | |
from django.conf import settings | |
if not getattr(settings, 'AUTH_PROFILE_MODULE', False): | |
raise SiteProfileNotAvailable('You need to set AUTH_PROFILE_MO' | |
'DULE in your project settings') | |
try: | |
app_label, model_name = settings.AUTH_PROFILE_MODULE.split('.') | |
except ValueError: | |
raise SiteProfileNotAvailable('app_label and model_name should' | |
' be separated by a dot in the AUTH_PROFILE_MODULE set' | |
'ting') | |
try: | |
model = models.get_model(app_label, model_name) | |
if model is None: | |
raise SiteProfileNotAvailable('Unable to load the profile ' | |
'model, check AUTH_PROFILE_MODULE in your project sett' | |
'ings') | |
self._profile_cache = model._default_manager.using(self._state.db).get(user__id__exact=self.id) | |
self._profile_cache.user = self | |
except (ImportError, ImproperlyConfigured): | |
raise SiteProfileNotAvailable | |
return self._profile_cache |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment