Changeset 1309
- Timestamp:
- 11/20/05 13:15:17 (3 years ago)
- Files:
-
- django/branches/new-admin/django/conf/global_settings.py (modified) (1 diff)
- django/branches/new-admin/django/middleware/sessions.py (modified) (2 diffs)
- django/branches/new-admin/docs/authentication.txt (modified) (3 diffs)
- django/branches/new-admin/docs/model-api.txt (modified) (2 diffs)
- django/branches/new-admin/docs/sessions.txt (modified) (3 diffs)
- django/branches/new-admin/docs/settings.txt (modified) (1 diff)
- django/branches/new-admin/docs/tutorial02.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/new-admin/django/conf/global_settings.py
r1255 r1309 197 197 SESSION_COOKIE_AGE = 60 * 60 * 24 * 7 * 2 # Age of cookie, in seconds (default: 2 weeks). 198 198 SESSION_COOKIE_DOMAIN = None # A string like ".lawrence.com", or None for standard domain cookie. 199 SESSION_SAVE_EVERY_REQUEST = False # Whether to save the session data on every request. 199 200 200 201 ######### 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 1 from django.conf.settings import SESSION_COOKIE_NAME, SESSION_COOKIE_AGE, SESSION_COOKIE_DOMAIN, SESSION_SAVE_EVERY_REQUEST 2 2 from django.models.core import sessions 3 3 from django.utils.cache import patch_vary_headers … … 68 68 except AttributeError: 69 69 modified = False 70 if modified :70 if modified or SESSION_SAVE_EVERY_REQUEST: 71 71 session_key = request.session.session_key or sessions.get_new_session_key() 72 72 new_session = sessions.save(session_key, request.session._session, django/branches/new-admin/docs/authentication.txt
r1223 r1309 50 50 * ``is_staff`` -- Boolean. Designates whether this user can access the 51 51 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 permission55 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. 56 56 * ``last_login`` -- A datetime of the user's last login. Is set to the 57 57 current date/time by default. … … 94 94 95 95 * ``has_perm(perm)`` -- Returns ``True`` if the user has the specified 96 permission .96 permission, where perm is in the format ``"package.codename"``. 97 97 98 98 * ``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"``. 100 101 101 102 * ``has_module_perms(package_name)`` -- Returns ``True`` if the user has … … 272 273 273 274 As 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 282 Here's the same thing, using Python 2.4's decorator syntax:: 274 283 275 284 from django.views.decorators.auth import user_passes_test django/branches/new-admin/docs/model-api.txt
r1301 r1309 964 964 Note that the scope of custom methods is modified to be the same as the module 965 965 scope. These methods do NOT have access to globals within your model's module. 966 Additionally, custom methods have access to a few commonly-used objects for 967 convenience: 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. 966 973 967 974 See `Giving models custom methods`_ for a full example. … … 1056 1063 if int(field_data) in BAD_CUSTOMER_IDS: 1057 1064 raise validators.ValidationError, "We don't deliver to this customer." 1065 1066 Executing custom SQL 1067 -------------------- 1068 1069 Feel free to write custom SQL statements in custom model methods and 1070 module-level methods. Each custom method automatically has access to the 1071 variable ``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])`` 1073 to execute the SQL and ``cursor.fetchone()`` or ``cursor.fetchall()`` to return 1074 the 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 1082 If your custom SQL statement alters the data in your database -- for example, 1083 via 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 1091 familiar with the Python DB-API, note that the SQL statement in 1092 ``cursor.execute()`` uses placeholders, ``"%s"``, rather than adding parameters 1093 directly within the SQL. If you use this technique, the underlying database 1094 library will automatically add quotes and escaping to your parameter(s) as 1095 necessary. 1096 1097 .. _Python DB-API: http://www.python.org/peps/pep-0249.html 1058 1098 1059 1099 Using models django/branches/new-admin/docs/sessions.txt
r1223 r1309 42 42 43 43 * ``__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. 45 46 46 47 * ``get(key, default=None)`` … … 159 160 {'user_id': 42} 160 161 161 Session cookies 162 =============== 163 164 A few `Django settings`_ give you control over the session cookie: 162 When sessions are saved 163 ======================= 164 165 By default, Django only saves to the session database when the session has been 166 modified -- that is if any of its dictionary values have been assigned or 167 deleted:: 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 183 behavior, set the ``SESSION_SAVE_EVERY_REQUEST`` setting to ``True``. If 184 ``SESSION_SAVE_EVERY_REQUEST`` is ``True``, Django will save the session to the 185 database on every single request. 186 187 Note that the session cookie is only sent when a session has been created or 188 modified. If ``SESSION_SAVE_EVERY_REQUEST`` is ``True``, the session cookie 189 will be sent on every request. 190 191 Similarly, the ``expires`` part of a session cookie is updated each time the 192 session cookie is sent. 193 194 Settings 195 ======== 196 197 A few `Django settings`_ give you control over session behavior: 165 198 166 199 SESSION_COOKIE_AGE … … 189 222 ``'hotclub'`` is a reference to the Hot Club of France, the band Django 190 223 Reinhardt played in. 224 225 SESSION_SAVE_EVERY_REQUEST 226 -------------------------- 227 228 Default: ``False`` 229 230 **Only available in Django development version.** 231 232 Whether 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 -- 234 that is, if any of its dictionary values have been assigned or deleted. 191 235 192 236 .. _Django settings: http://www.djangoproject.com/documentation/settings/ django/branches/new-admin/docs/settings.txt
r1255 r1309 534 534 Reinhardt played in. 535 535 536 SESSION_SAVE_EVERY_REQUEST 537 -------------------------- 538 539 Default: ``False`` 540 541 Whether to save the session data on every request. See the `session docs`_. 542 536 543 SITE_ID 537 544 ------- django/branches/new-admin/docs/tutorial02.txt
r1282 r1309 34 34 * Run the command ``django-admin.py install admin``. This will create an 35 35 extra database table that the admin needs. 36 * Edit your ``myproject .urls`` file and uncomment the line below36 * Edit your ``myproject/urls.py`` file and uncomment the line below 37 37 "Uncomment this for admin:". This file is a URLconf; we'll dig into 38 38 URLconfs in the next tutorial. For now, all you need to know is that it
