Django

Code

Changeset 1303

Show
Ignore:
Timestamp:
11/20/05 11:16:13 (2 years ago)
Author:
adrian
Message:

Added SESSION_SAVE_EVERY_REQUEST setting.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/conf/global_settings.py

    r1250 r1303  
    196196SESSION_COOKIE_AGE = 60 * 60 * 24 * 7 * 2 # Age of cookie, in seconds (default: 2 weeks). 
    197197SESSION_COOKIE_DOMAIN = None              # A string like ".lawrence.com", or None for standard domain cookie. 
     198SESSION_SAVE_EVERY_REQUEST = False        # Whether to save the session data on every request. 
    198199 
    199200######### 
  • django/trunk/django/middleware/sessions.py

    r1035 r1303  
    1 from django.conf.settings import SESSION_COOKIE_NAME, SESSION_COOKIE_AGE, SESSION_COOKIE_DOMAIN 
     1from django.conf.settings import SESSION_COOKIE_NAME, SESSION_COOKIE_AGE, SESSION_COOKIE_DOMAIN, SESSION_SAVE_EVERY_REQUEST 
    22from django.models.core import sessions 
    33from django.utils.cache import patch_vary_headers 
     
    6868        except AttributeError: 
    6969            modified = False 
    70         if modified
     70        if modified or SESSION_SAVE_EVERY_REQUEST
    7171            session_key = request.session.session_key or sessions.get_new_session_key() 
    7272            new_session = sessions.save(session_key, request.session._session, 
  • django/trunk/docs/sessions.txt

    r1211 r1303  
    4242 
    4343    * ``__delitem__(key)`` 
    44       Example: ``del request.session['fav_color']`` 
     44      Example: ``del request.session['fav_color']``. This raises ``KeyError`` 
     45      if the given ``key`` isn't already in the session. 
    4546 
    4647    * ``get(key, default=None)`` 
     
    159160    {'user_id': 42} 
    160161 
    161 Session cookies 
    162 =============== 
    163  
    164 A few `Django settings`_ give you control over the session cookie: 
     162When sessions are saved 
     163======================= 
     164 
     165By default, Django only saves to the session database when the session has been 
     166modified -- that is if any of its dictionary values have been assigned or 
     167deleted:: 
     168 
     169    # Session is modified. 
     170    request.session['foo'] = 'bar' 
     171 
     172    # Session is modified. 
     173    del request.session['foo'] 
     174 
     175    # Session is modified. 
     176    request.session['foo'] = {} 
     177 
     178    # Gotcha: Session is NOT modified, because this alters 
     179    # request.session['foo'] instead of request.session. 
     180    request.session['foo']['bar'] = 'baz' 
     181 
     182To change this default behavior, set the ``SESSION_SAVE_EVERY_REQUEST`` setting 
     183to ``True``. If ``SESSION_SAVE_EVERY_REQUEST`` is ``True``, Django will save 
     184the session to the database on every single request. 
     185 
     186Note that the session cookie is only sent when a session has been created or 
     187modified. If ``SESSION_SAVE_EVERY_REQUEST`` is ``True``, the session cookie 
     188will be sent on every request. 
     189 
     190Similarly, the ``expires`` part of a session cookie is updated each time the 
     191session cookie is sent. 
     192 
     193Settings 
     194======== 
     195 
     196A few `Django settings`_ give you control over session behavior: 
    165197 
    166198SESSION_COOKIE_AGE 
     
    189221``'hotclub'`` is a reference to the Hot Club of France, the band Django 
    190222Reinhardt played in. 
     223 
     224SESSION_SAVE_EVERY_REQUEST 
     225-------------------------- 
     226 
     227Default: ``False`` 
     228 
     229Whether to save the session data on every request. If this is ``False`` 
     230(default), then the session data will only be saved if it has been modified -- 
     231that is, if any of its dictionary values have been assigned or deleted. 
    191232 
    192233.. _Django settings: http://www.djangoproject.com/documentation/settings/ 
  • django/trunk/docs/settings.txt

    r1251 r1303  
    534534Reinhardt played in. 
    535535 
     536SESSION_SAVE_EVERY_REQUEST 
     537-------------------------- 
     538 
     539Default: ``False`` 
     540 
     541Whether to save the session data on every request. See the `session docs`_. 
     542 
    536543SITE_ID 
    537544-------