0
0
mirror of https://github.com/django/django.git synced 2024-11-30 15:10:46 +01:00

Renamed date_to_format function in docs/templates_python.txt example so as to make it not sound like a conversion function. Thanks, linoj

git-svn-id: http://code.djangoproject.com/svn/django/trunk@4502 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty 2007-02-13 15:44:04 +00:00
parent 7ac5a6e27d
commit c61d7e195f

View File

@ -829,12 +829,12 @@ Now your tag should begin to look like this::
def do_format_time(parser, token):
try:
# split_contents() knows not to split quoted strings.
tag_name, date_to_format, format_string = token.split_contents()
tag_name, date_to_be_formatted, format_string = token.split_contents()
except ValueError:
raise template.TemplateSyntaxError, "%r tag requires exactly two arguments" % token.contents[0]
if not (format_string[0] == format_string[-1] and format_string[0] in ('"', "'")):
raise template.TemplateSyntaxError, "%r tag's argument should be in quotes" % tag_name
return FormatTimeNode(date_to_format, format_string[1:-1])
return FormatTimeNode(date_to_be_formatted, format_string[1:-1])
You also have to change the renderer to retrieve the actual contents of the
``date_updated`` property of the ``blog_entry`` object. This can be
@ -846,13 +846,13 @@ current context, available in the ``render`` method::
from django.template import resolve_variable
import datetime
class FormatTimeNode(template.Node):
def __init__(self, date_to_format, format_string):
self.date_to_format = date_to_format
def __init__(self, date_to_be_formatted, format_string):
self.date_to_be_formatted = date_to_be_formatted
self.format_string = format_string
def render(self, context):
try:
actual_date = resolve_variable(self.date_to_format, context)
actual_date = resolve_variable(self.date_to_be_formatted, context)
return actual_date.strftime(self.format_string)
except VariableDoesNotExist:
return ''