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


Python settings.SESSION_COOKIE_AGE屬性代碼示例

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


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

示例1: get_expiry_age

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SESSION_COOKIE_AGE [as 別名]
def get_expiry_age(self, **kwargs):
        """Get the number of seconds until the session expires.

        Optionally, this function accepts `modification` and `expiry` keyword
        arguments specifying the modification and expiry of the session.
        """
        try:
            modification = kwargs['modification']
        except KeyError:
            modification = timezone.now()
        # Make the difference between "expiry=None passed in kwargs" and
        # "expiry not passed in kwargs", in order to guarantee not to trigger
        # self.load() when expiry is provided.
        try:
            expiry = kwargs['expiry']
        except KeyError:
            expiry = self.get('_session_expiry')

        if not expiry:   # Checks both None and 0 cases
            return settings.SESSION_COOKIE_AGE
        if not isinstance(expiry, datetime):
            return expiry
        delta = expiry - modification
        return delta.days * 86400 + delta.seconds 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:26,代碼來源:base.py

示例2: get_expiry_date

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SESSION_COOKIE_AGE [as 別名]
def get_expiry_date(self, **kwargs):
        """Get session the expiry date (as a datetime object).

        Optionally, this function accepts `modification` and `expiry` keyword
        arguments specifying the modification and expiry of the session.
        """
        try:
            modification = kwargs['modification']
        except KeyError:
            modification = timezone.now()
        # Same comment as in get_expiry_age
        try:
            expiry = kwargs['expiry']
        except KeyError:
            expiry = self.get('_session_expiry')

        if isinstance(expiry, datetime):
            return expiry
        if not expiry:   # Checks both None and 0 cases
            expiry = settings.SESSION_COOKIE_AGE
        return modification + timedelta(seconds=expiry) 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:23,代碼來源:base.py

示例3: load

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SESSION_COOKIE_AGE [as 別名]
def load(self):
        """
        Load the data from the key itself instead of fetching from some
        external data store. Opposite of _get_session_key(), raise BadSignature
        if signature fails.
        """
        try:
            return signing.loads(
                self.session_key,
                serializer=self.serializer,
                # This doesn't handle non-default expiry dates, see #19201
                max_age=settings.SESSION_COOKIE_AGE,
                salt='django.contrib.sessions.backends.signed_cookies',
            )
        except Exception:
            # BadSignature, ValueError, or unpickling exceptions. If any of
            # these happen, reset the session.
            self.create()
        return {} 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:21,代碼來源:signed_cookies.py

示例4: process_response

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SESSION_COOKIE_AGE [as 別名]
def process_response(self, request, response):
        """
        If the current session is fresh (was just created by the default
        session middleware, setting its expiry to `SESSION_COOKIE_AGE`)
        or the session is configured to keep alive, processes all rules
        to identify what `expiry` should be set.
        """
        if not (hasattr(request, 'user') and hasattr(request, 'session')):
            return response

        key = get_settings_key(request.user)

        fresh_session = (
            request.session.get_expiry_age() == settings.SESSION_COOKIE_AGE
        )
        keep_alive = getattr(
            settings, 'EXPIRY_{}_KEEP_ALIVE'.format(key), False
        )

        if fresh_session or keep_alive:
            process_rules(request=request, user=request.user)

        return response 
開發者ID:ramonsaraiva,項目名稱:django-expiry,代碼行數:25,代碼來源:middleware.py

示例5: get_expiry_date

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SESSION_COOKIE_AGE [as 別名]
def get_expiry_date(self, **kwargs):
        """Get session the expiry date (as a datetime object).

        Optionally, this function accepts `modification` and `expiry` keyword
        arguments specifying the modification and expiry of the session.
        """
        try:
            modification = kwargs['modification']
        except KeyError:
            modification = timezone.now()
        # Same comment as in get_expiry_age
        try:
            expiry = kwargs['expiry']
        except KeyError:
            expiry = self.get('_session_expiry')

        if isinstance(expiry, datetime):
            return expiry
        expiry = expiry or settings.SESSION_COOKIE_AGE   # Checks both None and 0 cases
        return modification + timedelta(seconds=expiry) 
開發者ID:PacktPublishing,項目名稱:Hands-On-Application-Development-with-PyCharm,代碼行數:22,代碼來源:base.py

示例6: load

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SESSION_COOKIE_AGE [as 別名]
def load(self):
        """
        We load the data from the key itself instead of fetching from
        some external data store. Opposite of _get_session_key(),
        raises BadSignature if signature fails.
        """
        try:
            return signing.loads(self.session_key,
                serializer=self.serializer,
                # This doesn't handle non-default expiry dates, see #19201
                max_age=settings.SESSION_COOKIE_AGE,
                salt='django.contrib.sessions.backends.signed_cookies')
        except Exception:
            # BadSignature, ValueError, or unpickling exceptions. If any of
            # these happen, reset the session.
            self.create()
        return {} 
開發者ID:drexly,項目名稱:openhgsenti,代碼行數:19,代碼來源:signed_cookies.py

示例7: load

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SESSION_COOKIE_AGE [as 別名]
def load(self):
        """
        We load the data from the key itself instead of fetching from
        some external data store. Opposite of _get_session_key(),
        raises BadSignature if signature fails.
        """
        try:
            return signing.loads(
                self.session_key,
                serializer=self.serializer,
                # This doesn't handle non-default expiry dates, see #19201
                max_age=settings.SESSION_COOKIE_AGE,
                salt='django.contrib.sessions.backends.signed_cookies',
            )
        except Exception:
            # BadSignature, ValueError, or unpickling exceptions. If any of
            # these happen, reset the session.
            self.create()
        return {} 
開發者ID:bpgc-cte,項目名稱:python2017,代碼行數:21,代碼來源:signed_cookies.py

示例8: synchronize_all_feeds

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SESSION_COOKIE_AGE [as 別名]
def synchronize_all_feeds():
    """Synchronize feeds every 30 minutes.

    To avoid a spike of load, the synchronization is spread over the whole
    period.

    Feeds that have their sync explicitly disabled or that have no active
    subscribers are not synchronized.
    """
    current_date = now()
    inactive_user_threshold = current_date - (timedelta(seconds=settings.SESSION_COOKIE_AGE) * 2)
    feeds_to_sync = models.Feed.objects.filter(
        is_sync_enabled=True,
        subscribers__user__is_active=True,
        subscribers__user__last_login__gte=inactive_user_threshold
    )

    ats = list()
    for i in range(0, 29):
        ats.append(current_date + timedelta(minutes=i))

    batch = Batch()
    for feed_id in feeds_to_sync.values_list('id', flat=True):
        batch.schedule_at('synchronize_feed', random.choice(ats), feed_id)
    tasks.schedule_batch(batch) 
開發者ID:NicolasLM,項目名稱:feedsubs,代碼行數:27,代碼來源:tasks.py

示例9: save

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SESSION_COOKIE_AGE [as 別名]
def save(self):
        '''Saves the session data to the datastore.'''
        time_till_expire = timedelta(seconds=settings.SESSION_COOKIE_AGE)
        expire_date = datetime.now() + time_till_expire
        
        if self._datastore_session:
            self._datastore_session.session_data = self.encode(self._session)
        else:
            self._datastore_session = Session(session_key=self.session_key, session_data=self.encode(self._session), expire_date=expire_date)
        self._datastore_session.put() 
開發者ID:elsigh,項目名稱:browserscope,代碼行數:12,代碼來源:datastore.py

示例10: load

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SESSION_COOKIE_AGE [as 別名]
def load(self):
        """
        We load the data from the key itself instead of fetching from
        some external data store. Opposite of _get_session_key(),
        raises BadSignature if signature fails.
        """
        try:
            return signing.loads(self.session_key,
                serializer=self.serializer,
                # This doesn't handle non-default expiry dates, see #19201
                max_age=settings.SESSION_COOKIE_AGE,
                salt='django.contrib.sessions.backends.signed_cookies')
        except (signing.BadSignature, ValueError):
            self.create()
        return {} 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:17,代碼來源:signed_cookies.py

示例11: _expiry_date

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SESSION_COOKIE_AGE [as 別名]
def _expiry_date(self, session_data):
        """
        Return the expiry time of the file storing the session's content.
        """
        expiry = session_data.get('_session_expiry')
        if not expiry:
            expiry = self._last_modification() + datetime.timedelta(seconds=settings.SESSION_COOKIE_AGE)
        return expiry 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:10,代碼來源:file.py

示例12: test_default_expiry

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SESSION_COOKIE_AGE [as 別名]
def test_default_expiry(self):
        # A normal session has a max age equal to settings
        self.assertEqual(
            self.session.get_expiry_age(), settings.SESSION_COOKIE_AGE
        )

        # So does a custom session with an idle expiration time of 0 (but it'll
        # expire at browser close)
        self.session.set_expiry(0)
        self.assertEqual(
            self.session.get_expiry_age(), settings.SESSION_COOKIE_AGE
        ) 
開發者ID:r4fek,項目名稱:django-cassandra-engine,代碼行數:14,代碼來源:test_sessions.py

示例13: test_custom_expiry_reset

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SESSION_COOKIE_AGE [as 別名]
def test_custom_expiry_reset(self):
        self.session.set_expiry(None)
        self.session.set_expiry(10)
        self.session.set_expiry(None)
        self.assertEqual(
            self.session.get_expiry_age(), settings.SESSION_COOKIE_AGE
        ) 
開發者ID:r4fek,項目名稱:django-cassandra-engine,代碼行數:9,代碼來源:test_sessions.py

示例14: _expiry_date

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SESSION_COOKIE_AGE [as 別名]
def _expiry_date(self, session_data):
        """
        Return the expiry time of the file storing the session's content.
        """
        return session_data.get('_session_expiry') or (
            self._last_modification() + datetime.timedelta(seconds=settings.SESSION_COOKIE_AGE)
        ) 
開發者ID:PacktPublishing,項目名稱:Hands-On-Application-Development-with-PyCharm,代碼行數:9,代碼來源:file.py

示例15: process_request

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import SESSION_COOKIE_AGE [as 別名]
def process_request(self, request):
        if not hasattr(request, "session") or request.session.is_empty():
            return

        init_time = request.session.setdefault(SESSION_TIMEOUT_KEY, time.time())

        expire_seconds = getattr(
            settings, "SESSION_EXPIRE_SECONDS", settings.SESSION_COOKIE_AGE
        )

        session_is_expired = time.time() - init_time > expire_seconds

        if session_is_expired:
            request.session.flush()
            redirect_url = getattr(settings, "SESSION_TIMEOUT_REDIRECT", None)
            if redirect_url:
                return redirect(redirect_url)
            else:
                return redirect_to_login(next=request.path)

        expire_since_last_activity = getattr(
            settings, "SESSION_EXPIRE_AFTER_LAST_ACTIVITY", False
        )
        grace_period = getattr(
            settings, "SESSION_EXPIRE_AFTER_LAST_ACTIVITY_GRACE_PERIOD", 1
        )

        if expire_since_last_activity and time.time() - init_time > grace_period:
            request.session[SESSION_TIMEOUT_KEY] = time.time() 
開發者ID:labd,項目名稱:django-session-timeout,代碼行數:31,代碼來源:middleware.py


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