Esempio n. 1
0
    def check_dependencies(self):
        """
        Check that all things needed to run the admin have been correctly installed.

        The default implementation checks that admin and contenttypes apps are
        installed, as well as the auth context processor.
        """
        app_cache.populate_apps()
        if not app_cache.has_app('django.contrib.admin'):
            raise ImproperlyConfigured("Put 'django.contrib.admin' in your "
                "INSTALLED_APPS setting in order to use the admin application.")
        if not app_cache.has_app('django.contrib.contenttypes'):
            raise ImproperlyConfigured("Put 'django.contrib.contenttypes' in "
                "your INSTALLED_APPS setting in order to use the admin application.")
        if 'django.contrib.auth.context_processors.auth' not in settings.TEMPLATE_CONTEXT_PROCESSORS:
            raise ImproperlyConfigured("Put 'django.contrib.auth.context_processors.auth' "
                "in your TEMPLATE_CONTEXT_PROCESSORS setting in order to use the admin application.")
Esempio n. 2
0
 def _session(self):
     """
     Obtains the current session variables.
     """
     if app_cache.has_app('django.contrib.sessions'):
         engine = import_module(settings.SESSION_ENGINE)
         cookie = self.cookies.get(settings.SESSION_COOKIE_NAME, None)
         if cookie:
             return engine.SessionStore(cookie.value)
     return {}
Esempio n. 3
0
    def login(self, **credentials):
        """
        Sets the Factory to appear as if it has successfully logged into a site.

        Returns True if login is possible; False if the provided credentials
        are incorrect, or the user is inactive, or if the sessions framework is
        not available.
        """
        user = authenticate(**credentials)
        if (user and user.is_active and
                app_cache.has_app('django.contrib.sessions')):
            engine = import_module(settings.SESSION_ENGINE)

            # Create a fake request that goes through request middleware
            request = self.request().request_instance

            if self.session:
                request.session = self.session
            else:
                request.session = engine.SessionStore()
            login(request, user)

            # Save the session values.
            request.session.save()

            # Set the cookie to represent the session.
            session_cookie = settings.SESSION_COOKIE_NAME
            self.cookies[session_cookie] = request.session.session_key
            cookie_data = {
                'max-age': None,
                'path': '/',
                'domain': settings.SESSION_COOKIE_DOMAIN,
                'secure': settings.SESSION_COOKIE_SECURE or None,
                'expires': None,
            }
            self.cookies[session_cookie].update(cookie_data)

            return True
        else:
            return False
Esempio n. 4
0
def skipUnlessAuthIsInstalled(func):
    return skipUnless(
        app_cache.has_app('django.contrib.auth'),
        "django.contrib.auth isn't installed")(func)
Esempio n. 5
0
from django.apps import app_cache
from django.template import Library

register = Library()

if app_cache.has_app('django.contrib.staticfiles'):
    from django.contrib.staticfiles.templatetags.staticfiles import static
else:
    from django.templatetags.static import static

static = register.simple_tag(static)
Esempio n. 6
0
 def __init__(self):
     if not app_cache.has_app('django.contrib.sites'):
         raise ImproperlyConfigured(
             "You cannot use RedirectFallbackMiddleware when "
             "django.contrib.sites is not installed."
         )