當前位置: 首頁>>代碼示例>>Python>>正文


Python settings.SESSION_ENGINE屬性代碼示例

本文整理匯總了Python中django.conf.settings.SESSION_ENGINE屬性的典型用法代碼示例。如果您正苦於以下問題:Python settings.SESSION_ENGINE屬性的具體用法?Python settings.SESSION_ENGINE怎麽用?Python settings.SESSION_ENGINE使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在django.conf.settings的用法示例。


在下文中一共展示了settings.SESSION_ENGINE屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: check

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SESSION_ENGINE [as 別名]
def check(cls, **kwargs):
        """
        We use .session_key and CSRF_COOKIE above: check that they will be there, and fail fast if not.
        """
        errors = super().check(**kwargs)

        # Ensure we are using the database session store. (Other SessionStores may also have .session_key?)
        engine = import_module(settings.SESSION_ENGINE)
        store = engine.SessionStore
        if not issubclass(store, DatabaseSessionStore):
            errors.append(Error(
                "Quiz logging uses request.session.session_key, which likely implies "
                "SESSION_ENGINE = 'django.contrib.sessions.backends.db' in settings."
            ))

        if 'django.middleware.csrf.CsrfViewMiddleware' not in settings.MIDDLEWARE:
            errors.append(Error(
                "CsrfViewMiddleware is not enabled in settings: quiz logging uses CSRF_COOKIE and will fail without "
                "CSRF checking enabled. Also it should be enabled in general."
            ))

        return errors 
開發者ID:sfu-fas,項目名稱:coursys,代碼行數:24,代碼來源:models.py

示例2: logout

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SESSION_ENGINE [as 別名]
def logout(self):
        """
        Removes the authenticated user's cookies and session object.

        Causes the authenticated user to be logged out.
        """
        from django.contrib.auth import get_user, logout

        request = HttpRequest()
        engine = import_module(settings.SESSION_ENGINE)
        if self.session:
            request.session = self.session
            request.user = get_user(request)
        else:
            request.session = engine.SessionStore()
        logout(request)
        self.cookies = SimpleCookie() 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:19,代碼來源:client.py

示例3: simulate_login

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SESSION_ENGINE [as 別名]
def simulate_login(username, password, headers=None):
    rf = RequestFactory()
    request = rf.request(**headers)
    engine = import_module(settings.SESSION_ENGINE)
    request.session = engine.SessionStore()

    # TODO remove when we don't support Django 1.10 anymore
    # request passed in to authenticate only after Django 1.10
    # Also the middleware saving the request to thread local can be dropped
    try:
        user = authenticate(request, username=username, password=password)
    except TypeError:
        middleware.thread_data.request = request
        user = authenticate(username=username, password=password)
    if user:
        login(request, user) 
開發者ID:muccg,項目名稱:django-useraudit,代碼行數:18,代碼來源:utils.py

示例4: establish_session

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SESSION_ENGINE [as 別名]
def establish_session(original_function):
    '''
    Simulate establishing a session.

    Adapted from https://code.djangoproject.com/ticket/10899 and
    http://blog.joshcrompton.com/2012/09/how-to-use-sessions-in-django-unit-tests.html

    FIXME this needs its own tests

    '''
    def new_function(self, *args, **kwargs):
        from importlib import import_module
        from django.conf import settings

        engine = import_module(settings.SESSION_ENGINE)
        store = engine.SessionStore()
        store.save()  # we need to make load() work, or the cookie is worthless

        self.client.cookies[settings.SESSION_COOKIE_NAME] = store.session_key
        self.session_key = store.session_key

        original_function(self, *args, **kwargs)
    return new_function 
開發者ID:metabolize,項目名稱:drf-to-s3,代碼行數:25,代碼來源:util.py

示例5: test_post_logout_cycle_session

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SESSION_ENGINE [as 別名]
def test_post_logout_cycle_session(self):
        user = create_user()
        data = {"new_password": "new password", "current_password": "secret"}
        login_user(self.client, user)
        self.client.force_login(user)

        response = self.client.post(self.base_url, data)
        self.assert_status_equal(response, status.HTTP_204_NO_CONTENT)

        user.refresh_from_db()

        session_id = self.client.cookies['sessionid'].coded_value
        engine = importlib.import_module(settings.SESSION_ENGINE)
        session = engine.SessionStore(session_id)
        session_key = session[HASH_SESSION_KEY]

        self.assertEqual(session_key, user.get_session_auth_hash()) 
開發者ID:sunscrapers,項目名稱:djoser,代碼行數:19,代碼來源:test_set_password.py

示例6: delete_expired_sessions_and_workflows_forever

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SESSION_ENGINE [as 別名]
def delete_expired_sessions_and_workflows_forever():
    if settings.SESSION_ENGINE != "django.contrib.sessions.backends.db":
        warnings.warn(
            "WARNING: not deleting anonymous workflows because we do not know "
            "which sessions are expired. Rewrite "
            "delete_expired_sessions_and_workflows() to fix this problem."
        )
        # Run forever
        while True:
            await asyncio.sleep(999999)

    while True:
        try:
            await benchmark(
                logger,
                delete_expired_sessions_and_workflows(),
                "delete_expired_sessions_and_workflows()",
            )
        except:
            logger.exception("Error deleting expired sessions and workflows")
        await asyncio.sleep(ExpiryInterval) 
開發者ID:CJWorkbench,項目名稱:cjworkbench,代碼行數:23,代碼來源:main.py

示例7: login_user

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SESSION_ENGINE [as 別名]
def login_user(self, userid):
        """
        Login as specified user, does not depend on auth backend (hopefully)

        This is based on Client.login() with a small hack that does not
        require the call to authenticate()
        """
        if not 'django.contrib.sessions' in settings.INSTALLED_APPS:
            raise AssertionError("Unable to login without django.contrib.sessions in INSTALLED_APPS")
        try:
            user = User.objects.get(username=userid)
        except User.DoesNotExist:
            user = User(username=userid, password='')
            user.save()
        user.backend = "%s.%s" % ("django.contrib.auth.backends",
                                  "ModelBackend")
        engine = import_module(settings.SESSION_ENGINE)

        # Create a fake request to store login details.
        request = HttpRequest()
        #if self.session:
        #    request.session = self.session
        #else:
        request.session = engine.SessionStore()
        login(request, user)

        # 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)

        # Save the session values.
        request.session.save() 
開發者ID:sfu-fas,項目名稱:coursys,代碼行數:42,代碼來源:testing.py

示例8: setUp

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SESSION_ENGINE [as 別名]
def setUp(self):
        classify = Classification.objects.create(c_name='test')
        self.art = Article.objects.create(caption='article',
                                          sub_caption='sub_article',
                                          classification=classify,
                                          content='article test',
                                          publish=True)
        settings.SESSION_ENGINE = 'django.contrib.sessions.backends.file'
        engine = import_module(settings.SESSION_ENGINE)
        store = engine.SessionStore()
        store.save()
        self.session = store
        self.client.cookies[settings.SESSION_COOKIE_NAME] = store.session_key 
開發者ID:bluedazzle,項目名稱:django-angularjs-blog,代碼行數:15,代碼來源:test_view_blog.py

示例9: _session

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SESSION_ENGINE [as 別名]
def _session(self):
        """
        Obtains the current session variables.
        """
        if apps.is_installed('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)
            else:
                s = engine.SessionStore()
                s.save()
                self.cookies[settings.SESSION_COOKIE_NAME] = s.session_key
                return s
        return {} 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:17,代碼來源:client.py

示例10: login

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SESSION_ENGINE [as 別名]
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.
        """
        from django.contrib.auth import authenticate, login
        user = authenticate(**credentials)
        if (user and user.is_active and
                apps.is_installed('django.contrib.sessions')):
            engine = import_module(settings.SESSION_ENGINE)

            # Create a fake request to store login details.
            request = HttpRequest()

            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 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:43,代碼來源:client.py

示例11: __init__

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SESSION_ENGINE [as 別名]
def __init__(self):
        engine = import_module(settings.SESSION_ENGINE)
        self.SessionStore = engine.SessionStore 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:5,代碼來源:middleware.py

示例12: handle

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SESSION_ENGINE [as 別名]
def handle(self, **options):
        engine = import_module(settings.SESSION_ENGINE)
        try:
            engine.SessionStore.clear_expired()
        except NotImplementedError:
            self.stderr.write("Session engine '%s' doesn't support clearing "
                              "expired sessions.\n" % settings.SESSION_ENGINE) 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:9,代碼來源:clearsessions.py

示例13: get_session_store_class

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SESSION_ENGINE [as 別名]
def get_session_store_class(cls):
        return import_module(settings.SESSION_ENGINE).SessionStore 
開發者ID:QueraTeam,項目名稱:django-qsessions,代碼行數:4,代碼來源:models.py

示例14: __init__

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SESSION_ENGINE [as 別名]
def __init__(self, method = 'GET'):
        super(EnhancedHttpRequest, self).__init__()
        self.method = method

        session_engine = import_module(settings.SESSION_ENGINE)
        self.session = session_engine.SessionStore(session_key = None) 
開發者ID:hspandher,項目名稱:django-test-addons,代碼行數:8,代碼來源:utils.py

示例15: create_session

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SESSION_ENGINE [as 別名]
def create_session(self):
        session_engine = import_module(settings.SESSION_ENGINE)
        store = session_engine.SessionStore()
        store.save()
        self.client.cookies[settings.SESSION_COOKIE_NAME] = store.session_key 
開發者ID:hspandher,項目名稱:django-test-addons,代碼行數:7,代碼來源:utils.py


注:本文中的django.conf.settings.SESSION_ENGINE屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。