当前位置: 首页>>代码示例>>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;未经允许,请勿转载。