Django

Code

Changeset 1309

Show
Ignore:
Timestamp:
11/20/05 13:15:17 (3 years ago)
Author:
rjwittams
Message:

Merge to trunk r1307

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/new-admin/django/conf/global_settings.py

    r1255 r1309  
    197197SESSION_COOKIE_AGE = 60 * 60 * 24 * 7 * 2 # Age of cookie, in seconds (default: 2 weeks). 
    198198SESSION_COOKIE_DOMAIN = None              # A string like ".lawrence.com", or None for standard domain cookie. 
     199SESSION_SAVE_EVERY_REQUEST = False        # Whether to save the session data on every request. 
    199200 
    200201######### 
  • django/branches/new-admin/django/middleware/sessions.py

    r1041 r1309  
    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/branches/new-admin/docs/authentication.txt

    r1223 r1309  
    5050    * ``is_staff`` -- Boolean. Designates whether this user can access the 
    5151      admin site. 
    52     * ``is_active`` -- Boolean. Designates whether this user account is valid. 
    53       Set this to ``False`` instead of deleting accounts. 
    54     * ``is_superuser`` -- Boolean. Designates whether this user has permission 
    55       to do anything (according to the permission system)
     52    * ``is_active`` -- Boolean. Designates whether this user can log into the 
     53      Django admin. Set this to ``False`` instead of deleting accounts. 
     54    * ``is_superuser`` -- Boolean. Designates that this user has all permissions 
     55      without explicitly assigning them
    5656    * ``last_login`` -- A datetime of the user's last login. Is set to the 
    5757      current date/time by default. 
     
    9494 
    9595    * ``has_perm(perm)`` -- Returns ``True`` if the user has the specified 
    96       permission
     96      permission, where perm is in the format ``"package.codename"``
    9797 
    9898    * ``has_perms(perm_list)`` -- Returns ``True`` if the user has each of the 
    99       specified permissions. 
     99      specified permissions, where each perm is in the format 
     100      ``"package.codename"``. 
    100101 
    101102    * ``has_module_perms(package_name)`` -- Returns ``True`` if the user has 
     
    272273 
    273274As a shortcut, you can use the convenient ``user_passes_test`` decorator:: 
     275 
     276    from django.views.decorators.auth import user_passes_test 
     277 
     278    def my_view(request): 
     279        # ... 
     280    my_view = user_passes_test(my_view, lambda u: u.has_perm('polls.can_vote')) 
     281 
     282Here's the same thing, using Python 2.4's decorator syntax:: 
    274283 
    275284    from django.views.decorators.auth import user_passes_test 
  • django/branches/new-admin/docs/model-api.txt

    r1301 r1309  
    964964Note that the scope of custom methods is modified to be the same as the module 
    965965scope. These methods do NOT have access to globals within your model's module. 
     966Additionally, custom methods have access to a few commonly-used objects for 
     967convenience: 
     968 
     969    * The ``datetime`` module from Python's standard library. 
     970    * The ``db`` object from ``django.core.db``. This represents the database 
     971      connection, so you can do custom queries via a cursor object. See 
     972      "Executing custom SQL" below. 
    966973 
    967974See `Giving models custom methods`_ for a full example. 
     
    10561063            if int(field_data) in BAD_CUSTOMER_IDS: 
    10571064                raise validators.ValidationError, "We don't deliver to this customer." 
     1065 
     1066Executing custom SQL 
     1067-------------------- 
     1068 
     1069Feel free to write custom SQL statements in custom model methods and 
     1070module-level methods. Each custom method automatically has access to the 
     1071variable ``db``, which is the current database connection. To use it, call 
     1072``db.cursor()`` to get a cursor object. Then, call ``cursor.execute(sql, [params])`` 
     1073to execute the SQL and ``cursor.fetchone()`` or ``cursor.fetchall()`` to return 
     1074the resulting rows. Example:: 
     1075 
     1076    def my_custom_sql(self): 
     1077        cursor = db.cursor() 
     1078        cursor.execute("SELECT foo FROM bar WHERE baz = %s", [self.baz]) 
     1079        row = cursor.fetchone() 
     1080        return row 
     1081 
     1082If your custom SQL statement alters the data in your database -- for example, 
     1083via a ``DELETE`` or ``UPDATE`` -- you'll need to call ``db.commit()``. Example:: 
     1084 
     1085    def my_custom_sql2(self): 
     1086        cursor = db.cursor() 
     1087        cursor.execute("DELETE FROM bar WHERE baz = %s", [self.baz]) 
     1088        db.commit() 
     1089 
     1090``db`` and ``cursor`` simply use the standard `Python DB-API`_. If you're not 
     1091familiar with the Python DB-API, note that the SQL statement in 
     1092``cursor.execute()`` uses placeholders, ``"%s"``, rather than adding parameters 
     1093directly within the SQL. If you use this technique, the underlying database 
     1094library will automatically add quotes and escaping to your parameter(s) as 
     1095necessary. 
     1096 
     1097.. _Python DB-API: http://www.python.org/peps/pep-0249.html 
    10581098 
    10591099Using models 
  • django/branches/new-admin/docs/sessions.txt

    r1223 r1309  
    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 
     182**Only available in Django development version.** To change this default 
     183behavior, set the ``SESSION_SAVE_EVERY_REQUEST`` setting  to ``True``. If 
     184``SESSION_SAVE_EVERY_REQUEST`` is ``True``, Django will save the session to the 
     185database on every single request. 
     186 
     187Note that the session cookie is only sent when a session has been created or 
     188modified. If ``SESSION_SAVE_EVERY_REQUEST`` is ``True``, the session cookie 
     189will be sent on every request. 
     190 
     191Similarly, the ``expires`` part of a session cookie is updated each time the 
     192session cookie is sent. 
     193 
     194Settings 
     195======== 
     196 
     197A few `Django settings`_ give you control over session behavior: 
    165198 
    166199SESSION_COOKIE_AGE 
     
    189222``'hotclub'`` is a reference to the Hot Club of France, the band Django 
    190223Reinhardt played in. 
     224 
     225SESSION_SAVE_EVERY_REQUEST 
     226-------------------------- 
     227 
     228Default: ``False`` 
     229 
     230**Only available in Django development version.** 
     231 
     232Whether to save the session data on every request. If this is ``False`` 
     233(default), then the session data will only be saved if it has been modified -- 
     234that is, if any of its dictionary values have been assigned or deleted. 
    191235 
    192236.. _Django settings: http://www.djangoproject.com/documentation/settings/ 
  • django/branches/new-admin/docs/settings.txt

    r1255 r1309  
    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------- 
  • django/branches/new-admin/docs/tutorial02.txt

    r1282 r1309  
    3434    * Run the command ``django-admin.py install admin``. This will create an 
    3535      extra database table that the admin needs. 
    36     * Edit your ``myproject.urls`` file and uncomment the line below 
     36    * Edit your ``myproject/urls.py`` file and uncomment the line below 
    3737      "Uncomment this for admin:". This file is a URLconf; we'll dig into 
    3838      URLconfs in the next tutorial. For now, all you need to know is that it