Skip to content

Commit

Permalink
Removed docs that assume developer might be using Python < 2.4
Browse files Browse the repository at this point in the history
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12400 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
spookylukey committed Feb 9, 2010
1 parent 4bff194 commit eaee55e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 52 deletions.
11 changes: 4 additions & 7 deletions docs/howto/custom-template-tags.txt
Expand Up @@ -138,8 +138,7 @@ The ``Library.filter()`` method takes two arguments:
2. The compilation function -- a Python function (not the name of the
function as a string).

If you're using Python 2.4 or above, you can use ``register.filter()`` as a
decorator instead::
You can use ``register.filter()`` as a decorator instead::

@register.filter(name='cut')
@stringfilter
Expand Down Expand Up @@ -557,8 +556,7 @@ The ``tag()`` method takes two arguments:
2. The compilation function -- a Python function (not the name of the
function as a string).

As with filter registration, it is also possible to use this as a decorator, in
Python 2.4 and above::
As with filter registration, it is also possible to use this as a decorator::

@register.tag(name="current_time")
def do_current_time(parser, token):
Expand Down Expand Up @@ -657,7 +655,7 @@ Our earlier ``current_time`` function could thus be written like this::

register.simple_tag(current_time)

In Python 2.4, the decorator syntax also works::
The decorator syntax also works::

@register.simple_tag
def current_time(format_string):
Expand Down Expand Up @@ -738,8 +736,7 @@ loader, we'd register the tag like this::
# Here, register is a django.template.Library instance, as before
register.inclusion_tag('results.html')(show_results)

As always, Python 2.4 decorator syntax works as well, so we could have
written::
As always, decorator syntax works as well, so we could have written::

@register.inclusion_tag('results.html')
def show_results(poll):
Expand Down
43 changes: 9 additions & 34 deletions docs/topics/auth.txt
Expand Up @@ -696,36 +696,19 @@ The login_required decorator

from django.contrib.auth.decorators import login_required

def my_view(request):
# ...
my_view = login_required(my_view)

Here's an equivalent example, using the more compact decorator syntax
introduced in Python 2.4::

from django.contrib.auth.decorators import login_required

@login_required
def my_view(request):
# ...
...

:func:`~django.contrib.auth.decorators.login_required` also takes an
optional ``redirect_field_name`` parameter. Example::

from django.contrib.auth.decorators import login_required

def my_view(request):
# ...
my_view = login_required(redirect_field_name='redirect_to')(my_view)

Again, an equivalent example of the more compact decorator syntax
introduced in Python 2.4::

from django.contrib.auth.decorators import login_required

@login_required(redirect_field_name='redirect_to')
def my_view(request):
# ...
...

:func:`~django.contrib.auth.decorators.login_required` does the following:

Expand Down Expand Up @@ -1058,23 +1041,15 @@ checks to make sure the user is logged in and has the permission

from django.contrib.auth.decorators import user_passes_test

@user_passes_test(lambda u: u.has_perm('polls.can_vote'))
def my_view(request):
# ...
my_view = user_passes_test(lambda u: u.has_perm('polls.can_vote'))(my_view)
...

We're using this particular test as a relatively simple example. However,
if you just want to test whether a permission is available to a user, you
can use the :func:`~django.contrib.auth.decorators.permission_required()`
decorator, described later in this document.

Here's the same thing, using Python 2.4's decorator syntax::

from django.contrib.auth.decorators import user_passes_test

@user_passes_test(lambda u: u.has_perm('polls.can_vote'))
def my_view(request):
# ...

:func:`~django.contrib.auth.decorators.user_passes_test` takes a required
argument: a callable that takes a
:class:`~django.contrib.auth.models.User` object and returns ``True`` if
Expand All @@ -1093,7 +1068,7 @@ checks to make sure the user is logged in and has the permission

@user_passes_test(lambda u: u.has_perm('polls.can_vote'), login_url='/login/')
def my_view(request):
# ...
...

The permission_required decorator
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand All @@ -1107,9 +1082,9 @@ The permission_required decorator

from django.contrib.auth.decorators import permission_required

permission_required('polls.can_vote')
def my_view(request):
# ...
my_view = permission_required('polls.can_vote')(my_view)
...

As for the :meth:`User.has_perm` method, permission names take the form
``"<app label>.<permission codename>"`` (i.e. ``polls.can_vote`` for a
Expand All @@ -1120,9 +1095,9 @@ The permission_required decorator

from django.contrib.auth.decorators import permission_required

permission_required('polls.can_vote', login_url='/loginpage/')
def my_view(request):
# ...
my_view = permission_required('polls.can_vote', login_url='/loginpage/')(my_view)
...

As in the :func:`~decorators.login_required` decorator, ``login_url``
defaults to :setting:`settings.LOGIN_URL <LOGIN_URL>`.
Expand Down
12 changes: 1 addition & 11 deletions docs/topics/cache.txt
Expand Up @@ -332,13 +332,6 @@ to use::

from django.views.decorators.cache import cache_page

def my_view(request):
...

my_view = cache_page(my_view, 60 * 15)

Or, using Python 2.4's decorator syntax::

@cache_page(60 * 15)
def my_view(request):
...
Expand All @@ -365,12 +358,9 @@ requested, subsequent requests to that URL will use the cache.
works in the same way as the ``CACHE_MIDDLEWARE_KEY_PREFIX`` setting for the
middleware. It can be used like this::

my_view = cache_page(my_view, 60 * 15, key_prefix="site1")

Or, using Python 2.4's decorator syntax::

@cache_page(60 * 15, key_prefix="site1")
def my_view(request):
...

Specifying per-view cache in the URLconf
----------------------------------------
Expand Down

0 comments on commit eaee55e

Please sign in to comment.