summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorJason Pellerin <jpellerin@gmail.com>2006-07-23 03:31:52 +0000
committerJason Pellerin <jpellerin@gmail.com>2006-07-23 03:31:52 +0000
commit438c23a6c6eb71b73272a9b98392af654b76c82c (patch)
treec9f9bdfd9db7efc982b5094ba452c5d152881b35 /docs
parentd345b89bc67b67867a4cc9608a972b7ffa6e0903 (diff)
[multi-db] Merge trunk to [3426]
git-svn-id: http://code.djangoproject.com/svn/django/branches/multiple-db-support@3427 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'docs')
-rw-r--r--docs/admin_css.txt4
-rw-r--r--docs/authentication.txt29
-rw-r--r--docs/cache.txt9
-rw-r--r--docs/django-admin.txt8
-rw-r--r--docs/faq.txt8
-rw-r--r--docs/model-api.txt18
-rw-r--r--docs/request_response.txt30
-rw-r--r--docs/tutorial01.txt2
-rw-r--r--docs/tutorial03.txt10
9 files changed, 84 insertions, 34 deletions
diff --git a/docs/admin_css.txt b/docs/admin_css.txt
index 069012a84b..ec402f7142 100644
--- a/docs/admin_css.txt
+++ b/docs/admin_css.txt
@@ -118,8 +118,8 @@ additional class on the ``a`` for that tool. These are ``.addlink`` and
Example from a changelist page::
<ul class="object-tools">
- <li><a href="/stories/add/" class="addlink">Add redirect</a></li>
- </ul>
+ <li><a href="/stories/add/" class="addlink">Add redirect</a></li>
+ </ul>
.. image:: http://media.djangoproject.com/img/doc/admincss/objecttools_01.gif
:alt: Object tools on a changelist page
diff --git a/docs/authentication.txt b/docs/authentication.txt
index 68b9024a90..d10dda28ef 100644
--- a/docs/authentication.txt
+++ b/docs/authentication.txt
@@ -95,7 +95,11 @@ In addition to those automatic API methods, ``User`` objects have the following
custom methods:
* ``is_anonymous()`` -- Always returns ``False``. This is a way of
- comparing ``User`` objects to anonymous users.
+ differentiating ``User`` and ``AnonymousUser`` objects. Generally, you
+ should prefer using ``is_authenticated()`` to this method.
+
+ * ``is_authenticated()`` -- Always returns ``True``. This is a way to
+ tell if the user has been authenticated.
* ``get_full_name()`` -- Returns the ``first_name`` plus the ``last_name``,
with a space in between.
@@ -219,6 +223,7 @@ the ``django.contrib.auth.models.User`` interface, with these differences:
* ``id`` is always ``None``.
* ``is_anonymous()`` returns ``True`` instead of ``False``.
+ * ``is_authenticated()`` returns ``False`` instead of ``True``.
* ``has_perm()`` always returns ``False``.
* ``set_password()``, ``check_password()``, ``save()``, ``delete()``,
``set_groups()`` and ``set_permissions()`` raise ``NotImplementedError``.
@@ -254,12 +259,12 @@ Once you have those middlewares installed, you'll be able to access
``request.user`` in views. ``request.user`` will give you a ``User`` object
representing the currently logged-in user. If a user isn't currently logged in,
``request.user`` will be set to an instance of ``AnonymousUser`` (see the
-previous section). You can tell them apart with ``is_anonymous()``, like so::
+previous section). You can tell them apart with ``is_authenticated()``, like so::
- if request.user.is_anonymous():
- # Do something for anonymous users.
+ if request.user.is_authenticated():
+ # Do something for authenticated users.
else:
- # Do something for logged-in users.
+ # Do something for anonymous users.
.. _request objects: http://www.djangoproject.com/documentation/request_response/#httprequest-objects
.. _session documentation: http://www.djangoproject.com/documentation/sessions/
@@ -323,19 +328,19 @@ The raw way
~~~~~~~~~~~
The simple, raw way to limit access to pages is to check
-``request.user.is_anonymous()`` and either redirect to a login page::
+``request.user.is_authenticated()`` and either redirect to a login page::
from django.http import HttpResponseRedirect
def my_view(request):
- if request.user.is_anonymous():
+ if not request.user.is_authenticated():
return HttpResponseRedirect('/login/?next=%s' % request.path)
# ...
...or display an error message::
def my_view(request):
- if request.user.is_anonymous():
+ if not request.user.is_authenticated():
return render_to_response('myapp/login_error.html')
# ...
@@ -439,7 +444,7 @@ For example, this view checks to make sure the user is logged in and has the
permission ``polls.can_vote``::
def my_view(request):
- if request.user.is_anonymous() or not request.user.has_perm('polls.can_vote'):
+ if not (request.user.is_authenticated() and request.user.has_perm('polls.can_vote')):
return HttpResponse("You can't vote in this poll.")
# ...
@@ -605,10 +610,10 @@ Users
The currently logged-in user, either a ``User`` instance or an``AnonymousUser``
instance, is stored in the template variable ``{{ user }}``::
- {% if user.is_anonymous %}
- <p>Welcome, new user. Please log in.</p>
+ {% if user.is_authenticated %}
+ <p>Welcome, {{ user.username }}. Thanks for logging in.</p>
{% else %}
- <p>Welcome, {{ user.username }}. Thanks for logging in.</p>
+ <p>Welcome, new user. Please log in.</p>
{% endif %}
Permissions
diff --git a/docs/cache.txt b/docs/cache.txt
index 2ef3d6503f..62fec289b9 100644
--- a/docs/cache.txt
+++ b/docs/cache.txt
@@ -230,8 +230,13 @@ Then, add the following required settings to your Django settings file:
collisions. Use an empty string if you don't care.
The cache middleware caches every page that doesn't have GET or POST
-parameters. Additionally, ``CacheMiddleware`` automatically sets a few headers
-in each ``HttpResponse``:
+parameters. Optionally, if the ``CACHE_MIDDLEWARE_ANONYMOUS_ONLY`` setting is
+``True``, only anonymous requests (i.e., not those made by a logged-in user)
+will be cached. This is a simple and effective way of disabling caching for any
+user-specific pages (include Django's admin interface).
+
+Additionally, ``CacheMiddleware`` automatically sets a few headers in each
+``HttpResponse``:
* Sets the ``Last-Modified`` header to the current date/time when a fresh
(uncached) version of the page is requested.
diff --git a/docs/django-admin.txt b/docs/django-admin.txt
index 04d86aa3b4..eb7b2dccd6 100644
--- a/docs/django-admin.txt
+++ b/docs/django-admin.txt
@@ -192,6 +192,14 @@ documentation.
.. _serving static files: http://www.djangoproject.com/documentation/static_files/
+Turning off auto-reload
+~~~~~~~~~~~~~~~~~~~~~~~
+
+To disable auto-reloading of code while the development server is running, use the
+``--noreload`` option, like so::
+
+ django-admin.py runserver --noreload
+
shell
-----
diff --git a/docs/faq.txt b/docs/faq.txt
index b374abfbf3..ccf8906c41 100644
--- a/docs/faq.txt
+++ b/docs/faq.txt
@@ -535,6 +535,14 @@ If you're sure your username and password are correct, make sure your user
account has ``is_active`` and ``is_staff`` set to True. The admin site only
allows access to users with those two fields both set to True.
+How can I prevent the cache middleware from caching the admin site?
+-------------------------------------------------------------------
+
+Set the ``CACHE_MIDDLEWARE_ANONYMOUS_ONLY`` setting to ``True``. See the
+`cache documentation`_ for more information.
+
+.. _cache documentation: ../cache/#the-per-site-cache
+
How do I automatically set a field's value to the user who last edited the object in the admin?
-----------------------------------------------------------------------------------------------
diff --git a/docs/model-api.txt b/docs/model-api.txt
index c4d57bf8c4..c369508c65 100644
--- a/docs/model-api.txt
+++ b/docs/model-api.txt
@@ -1225,6 +1225,24 @@ A few special cases to note about ``list_display``:
return self.birthday.strftime('%Y')[:3] + "0's"
decade_born_in.short_description = 'Birth decade'
+ * If the string given is a method of the model, Django will HTML-escape the
+ output by default. If you'd rather not escape the output of the method,
+ give the method an ``allow_tags`` attribute whose value is ``True``.
+
+ Here's a full example model::
+
+ class Person(models.Model):
+ first_name = models.CharField(maxlength=50)
+ last_name = models.CharField(maxlength=50)
+ color_code = models.CharField(maxlength=6)
+
+ class Admin:
+ list_display = ('first_name', 'last_name', 'colored_name')
+
+ def colored_name(self):
+ return '<span style="color: #%s;">%s %s</span>' % (self.color_code, self.first_name, self.last_name)
+ colored_name.allow_tags = True
+
``list_display_links``
----------------------
diff --git a/docs/request_response.txt b/docs/request_response.txt
index 0bcb3a7f5b..7480a6d3bb 100644
--- a/docs/request_response.txt
+++ b/docs/request_response.txt
@@ -106,12 +106,12 @@ All attributes except ``session`` should be considered read-only.
A ``django.contrib.auth.models.User`` object representing the currently
logged-in user. If the user isn't currently logged in, ``user`` will be set
to an instance of ``django.contrib.auth.models.AnonymousUser``. You
- can tell them apart with ``is_anonymous()``, like so::
+ can tell them apart with ``is_authenticated()``, like so::
- if request.user.is_anonymous():
- # Do something for anonymous users.
- else:
+ if request.user.is_authenticated():
# Do something for logged-in users.
+ else:
+ # Do something for anonymous users.
``user`` is only available if your Django installation has the
``AuthenticationMiddleware`` activated. For more, see
@@ -134,21 +134,25 @@ Methods
-------
``__getitem__(key)``
- Returns the GET/POST value for the given key, checking POST first, then
- GET. Raises ``KeyError`` if the key doesn't exist.
+ Returns the GET/POST value for the given key, checking POST first, then
+ GET. Raises ``KeyError`` if the key doesn't exist.
- This lets you use dictionary-accessing syntax on an ``HttpRequest``
- instance. Example: ``request["foo"]`` would return ``True`` if either
- ``request.POST`` or ``request.GET`` had a ``"foo"`` key.
+ This lets you use dictionary-accessing syntax on an ``HttpRequest``
+ instance. Example: ``request["foo"]`` would return ``True`` if either
+ ``request.POST`` or ``request.GET`` had a ``"foo"`` key.
``has_key()``
- Returns ``True`` or ``False``, designating whether ``request.GET`` or
- ``request.POST`` has the given key.
+ Returns ``True`` or ``False``, designating whether ``request.GET`` or
+ ``request.POST`` has the given key.
``get_full_path()``
- Returns the ``path``, plus an appended query string, if applicable.
+ Returns the ``path``, plus an appended query string, if applicable.
- Example: ``"/music/bands/the_beatles/?print=true"``
+ Example: ``"/music/bands/the_beatles/?print=true"``
+
+``is_secure()``
+ Returns ``True`` if the request is secure; that is, if it was made with
+ HTTPS.
QueryDict objects
-----------------
diff --git a/docs/tutorial01.txt b/docs/tutorial01.txt
index c353e1ab4b..62db8ab842 100644
--- a/docs/tutorial01.txt
+++ b/docs/tutorial01.txt
@@ -346,6 +346,8 @@ Note the following:
the SQL to the database.
If you're interested, also run the following commands:
+ * ``python manage.py validate polls`` -- Checks for any errors in the
+ construction of your models.
* ``python manage.py sqlinitialdata polls`` -- Outputs any initial data
required for Django's admin framework and your models.
diff --git a/docs/tutorial03.txt b/docs/tutorial03.txt
index 3a830eb76f..248d234043 100644
--- a/docs/tutorial03.txt
+++ b/docs/tutorial03.txt
@@ -189,7 +189,7 @@ publication date::
from django.http import HttpResponse
def index(request):
- latest_poll_list = Poll.objects.all().order_by('-pub_date')
+ latest_poll_list = Poll.objects.all().order_by('-pub_date')[:5]
output = ', '.join([p.question for p in latest_poll_list])
return HttpResponse(output)
@@ -202,7 +202,7 @@ So let's use Django's template system to separate the design from Python::
from django.http import HttpResponse
def index(request):
- latest_poll_list = Poll.objects.all().order_by('-pub_date')
+ latest_poll_list = Poll.objects.all().order_by('-pub_date')[:5]
t = loader.get_template('polls/index.html')
c = Context({
'latest_poll_list': latest_poll_list,
@@ -288,7 +288,7 @@ exception if a poll with the requested ID doesn't exist.
A shortcut: get_object_or_404()
-------------------------------
-It's a very common idiom to use ``get_object()`` and raise ``Http404`` if the
+It's a very common idiom to use ``get()`` and raise ``Http404`` if the
object doesn't exist. Django provides a shortcut. Here's the ``detail()`` view,
rewritten::
@@ -313,8 +313,8 @@ exist.
foremost design goals of Django is to maintain loose coupling.
There's also a ``get_list_or_404()`` function, which works just as
-``get_object_or_404()`` -- except using ``get_list()`` instead of
-``get_object()``. It raises ``Http404`` if the list is empty.
+``get_object_or_404()`` -- except using ``filter()`` instead of
+``get()``. It raises ``Http404`` if the list is empty.
Write a 404 (page not found) view
=================================