Ticket #2618: site_profiles.diff

File site_profiles.diff, 1.3 KB (added by jay@…, 18 years ago)
  • django/contrib/sites/models.py

     
    11from django.db import models
    22from django.utils.translation import gettext_lazy as _
     3from django.core.exceptions import ImproperlyConfigured
    34
     5class SiteProfileNotAvailable(Exception):
     6    pass
     7
    48class SiteManager(models.Manager):
    59    def get_current(self):
    610        from django.conf import settings
     
    2125
    2226    def __str__(self):
    2327        return self.domain
     28   
     29    def get_profile(self):
     30        """
     31        Returns profile for this site. Raises
     32        SiteProfileNotAvailable if this site does not allow profiles.
     33        """
     34        if not hasattr(self, '_profile_cache'):
     35            from django.conf import settings
     36            if not settings.SITE_PROFILE_MODULE:
     37                raise SiteProfileNotAvailable
     38            try:
     39                app_label, model_name = settings.SITE_PROFILE_MODULE.split('.')
     40                model = models.get_model(app_label, model_name)
     41                self._profile_cache = model._default_manager.get(site__id__exact=self.id)
     42            except (ImportError, ImproperlyConfigured):
     43                raise SiteProfileNotAvailable
     44        return self._profile_cache
Back to Top