Ticket #9091: 9091.diff

File 9091.diff, 4.4 KB (added by Marc Fargas, 16 years ago)

Patch

  • docs/howto/custom-template-tags.txt

    From 940edfc23f1764a46e69b2e878d4b8b68e540d55 Mon Sep 17 00:00:00 2001
    From: Marc Fargas <telenieko@telenieko.com>
    Date: Mon, 15 Sep 2008 17:00:36 +0200
    Subject: [PATCH] Rewrite of the variable resolution section, should go on the next 1.0
     Fixed wrong cross-reference in QueryDict.lists() docs.
    
    ---
     docs/howto/custom-template-tags.txt |   50 +++++++---------------------------
     docs/ref/request-response.txt       |    2 +-
     2 files changed, 12 insertions(+), 40 deletions(-)
    
    diff --git a/docs/howto/custom-template-tags.txt b/docs/howto/custom-template-tags.txt
    index e1ddefe..80a3d45 100644
    a b Now your tag should begin to look like this::  
    523523            raise template.TemplateSyntaxError, "%r tag's argument should be in quotes" % tag_name
    524524        return FormatTimeNode(date_to_be_formatted, format_string[1:-1])
    525525
     526.. versionchanged:: 1.0
     527    Variable resolution has changed in the 1.0 release of Django. ``template.resolve_variable()``
     528    has been deprecated in favor of a new ``template.Variable`` class.
     529
    526530You also have to change the renderer to retrieve the actual contents of the
    527531``date_updated`` property of the ``blog_entry`` object.  This can be
    528 accomplished by using the ``resolve_variable()`` function in
    529 ``django.template``. You pass ``resolve_variable()`` the variable name and the
    530 current context, available in the ``render`` method::
     532accomplished by using the ``Variable()`` class in ``django.template``.
     533
     534To use the ``Variable`` class, simply instantiate it with the name of the
     535variable to be resolved, and then call ``variable.resolve(context)``. So,
     536for example::
    531537
    532     from django import template
    533     from django.template import resolve_variable
    534     import datetime
    535538    class FormatTimeNode(template.Node):
    536539        def __init__(self, date_to_be_formatted, format_string):
    537             self.date_to_be_formatted = date_to_be_formatted
     540            self.date_to_be_formatted = Variable(date_to_be_formatted)
    538541            self.format_string = format_string
    539542
    540543        def render(self, context):
    541544            try:
    542                 actual_date = resolve_variable(self.date_to_be_formatted, context)
     545                actual_date = self.date_to_be_formatted.resolve(context)
    543546                return actual_date.strftime(self.format_string)
    544547            except template.VariableDoesNotExist:
    545548                return ''
    546549
    547 ``resolve_variable`` will try to resolve ``blog_entry.date_updated`` and then
    548 format it accordingly.
    549 
    550 .. versionadded:: 1.0
    551 
    552     Variable resolution has changed in the development version of Django.
    553     ``template.resolve_variable()`` is still available, but has been deprecated
    554     in favor of a new ``template.Variable`` class. Using this class will usually
    555     be more efficient than calling ``template.resolve_variable``
    556 
    557     To use the ``Variable`` class, simply instantiate it with the name of the
    558     variable to be resolved, and then call ``variable.resolve(context)``. So,
    559     in the development version, the above example would be more correctly
    560     written as:
    561 
    562     .. parsed-literal::
    563 
    564         class FormatTimeNode(template.Node):
    565             def __init__(self, date_to_be_formatted, format_string):
    566                 self.date_to_be_formatted = **Variable(date_to_be_formatted)**
    567                 self.format_string = format_string
    568 
    569             def render(self, context):
    570                 try:
    571                     actual_date = **self.date_to_be_formatted.resolve(context)**
    572                     return actual_date.strftime(self.format_string)
    573                 except template.VariableDoesNotExist:
    574                     return ''
    575 
    576     Changes are highlighted in bold.
    577 
    578550Variable resolution will throw a ``VariableDoesNotExist`` exception if it cannot
    579551resolve the string passed to it in the current context of the page.
    580552
  • docs/ref/request-response.txt

    diff --git a/docs/ref/request-response.txt b/docs/ref/request-response.txt
    index 89e5195..333a972 100644
    a b In addition, ``QueryDict`` has the following methods:  
    348348
    349349.. method:: QueryDict.lists()
    350350
    351     Like :method:items(), except it includes all values, as a list, for each
     351    Like :meth:`items()`, except it includes all values, as a list, for each
    352352    member of the dictionary. For example::
    353353   
    354354         >>> q = QueryDict('a=1&a=2&a=3')
Back to Top