def get_user_profile_model(): """ Returns site-specific profile for this user. Raises SiteProfileNotAvailable if this site does not allow profiles. """ global _user_profile_model_cache if _user_profile_model_cache: return _user_profile_model_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) # There is an issue with sphinx_build not being able to import the # profile model. Simply ignore the error in this case. if model is None and not getattr(settings, 'IS_SPHINX_BUILD_DUMMY', False): raise SiteProfileNotAvailable( 'Unable to load the profile ' 'model, check AUTH_PROFILE_MODULE in your project sett' 'ings') _user_profile_model_cache = model return model except (ImportError, ImproperlyConfigured): raise SiteProfileNotAvailable
def get_profile(self): """ Returns site-specific profile for this user. Raises SiteProfileNotAvailable if this site does not allow profiles. """ warnings.warn("The use of AUTH_PROFILE_MODULE to define user profiles has been deprecated.", DeprecationWarning, stacklevel=2) 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_MODULE 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 setting') 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 settings') 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
def get_profile_model(): if up_settings.USE_PROFILE: if not getattr(settings, 'AUTH_PROFILE_MODULE', False): raise SiteProfileNotAvailable( 'You need to set AUTH_PROFILE_MODULE 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 ' 'setting') 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') return model except (ImportError, ImproperlyConfigured): raise SiteProfileNotAvailable else: return None
def try_get_profile(user): """ Overwritten. Returns FacebookUserProfile. """ if not hasattr(user, '_profile_cache'): from django.conf import settings if not getattr(settings, 'FACEBOOK_PROFILE_MODULE', False): raise SiteProfileNotAvailable( 'You need to set FACEBOOK_PROFILE_MODULE in your project ' 'settings') try: app_label, model_name = settings.FACEBOOK_PROFILE_MODULE.split('.') except ValueError: raise SiteProfileNotAvailable( 'app_label and model_name should be separated by a dot in ' 'the FACEBOOK_PROFILE_MODULE setting') try: model = models.get_model(app_label, model_name) if model is None: raise SiteProfileNotAvailable( 'Unable to load the profile model, check ' 'FACEBOOK_PROFILE_MODULE in your project settings') user._profile_cache = model._default_manager.using( user._state.db).get(user__id__exact=user.id) user._profile_cache.user = user except (ImportError, ImproperlyConfigured): raise SiteProfileNotAvailable return user._profile_cache
def get_profile(self): """ Returns site-specific profile for this contact. Raises SiteProfileNotAvailable if this site does not allow profiles. """ if not hasattr(self, '_profile_cache'): from django.conf import settings if not getattr(settings, 'CYCLOPE_CONTACTS_PROFILE_MODULE', False): raise SiteProfileNotAvailable( 'You need to set CYCLOPE_CONTACTS' '_PROFILE_MODULE in your project settings') try: app_label, model_name = settings.CYCLOPE_CONTACTS_PROFILE_MODULE.split( '.') except ValueError: raise SiteProfileNotAvailable( 'app_label and model_name should' ' be separated by a dot in the CYCLOPE_CONTACTS_PROFILE' '_MODULE setting') try: model = models.get_model(app_label, model_name) if model is None: raise SiteProfileNotAvailable( 'Unable to load the profile ' 'model, check CYCLOPE_CONTACTS_PROFILE_MODULE in your ' 'project settings') self._profile_cache = model._default_manager.using( self._state.db).get(contact__id__exact=self.id) self._profile_cache.user = self except (ImportError, ImproperlyConfigured): raise SiteProfileNotAvailable return self._profile_cache
def get_profile(): user = instance if not hasattr(user, '_profile_cache'): from django.conf import settings if not getattr(settings, 'AUTH_PROFILE_MODULE', False): raise SiteProfileNotAvailable( 'You need to set AUTH_PROFILE_MODULE 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 setting' ) 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 settings' ) user._profile_cache, _ = model._default_manager.using( user._state.db).get_or_create(user=user) user._profile_cache.user = user except (ImportError, ImproperlyConfigured): raise SiteProfileNotAvailable return user._profile_cache
def handle(self, **options): """ Basically just copied from django.contrib.auth.User.get_profile """ 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: UserProfile = models.get_model(app_label, model_name) if UserProfile is None: raise SiteProfileNotAvailable('Unable to load the profile '\ 'model, check AUTH_PROFILE_MODULE in your project sett'\ 'ings') point_field = getattr(settings, 'USERRANK_POINT_FIELD', 'points') for profile in UserProfile.objects.all(): setattr(profile, point_field, profile.get_points()) profile.save() for rank, i in enumerate( UserProfile.objects.order_by('-%s' % point_field)): i.rank_cache = rank + 1 i.save() ranked_users = UserProfile.objects.filter( **{'%s__gt' % point_field: 0}) if getattr(settings, 'USERRANK_EXCLUDE_STAFF', False): ranked_users = ranked_users.exclude(user__is_staff=True) bottom = 0 top = 0 for i in settings.USERRANK_TIERS: # (Rank Name, percentile) aka ("Squire", .20) bottom = int(ranked_users.count() * (1 - i[1])) ranked_users.filter(rank_cache__range=(top, bottom)).update( rank_title=i[0]) top = bottom + 1 except (ImportError, ImproperlyConfigured): raise SiteProfileNotAvailable
def __init__(self): """Checks if there's a user profile.""" if not getattr(settings, 'AUTH_PROFILE_MODULE', False): raise SiteProfileNotAvailable( 'You need to set AUTH_PROFILE_MODULE 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 setting') self.model = models.get_model(app_label, model_name) if self.model is None: raise SiteProfileNotAvailable( 'Unable to load the profile model, check' ' AUTH_PROFILE_MODULE in your project settings') if not hasattr(self.model(), 'interval'): raise SiteProfileNotAvailable('Model has no field "interval"')
def _get_model_from_auth_profile_module(): """ Get model for UserProfile. The call 'request.user.get_profile()' can raise two types of Exceptions: - AttributeError if request.user is anonymous. - <UserProfileModel>.DoesNotExist if UserProfile have to be create yet. """ if not hasattr(settings, 'AUTH_PROFILE_MODULE'): exc_txt = "To use AccessAccount, you need to subclass AccessAccount" exc_txt += " abstract Model and define AUTH_PROFILE_MODULE coerently." raise SiteProfileNotAvailable(_(exc_txt)) app_label, model_name = settings.AUTH_PROFILE_MODULE.split('.') return get_model(app_label, model_name)