diff options
| author | Jeremy Dunck <jdunck@gmail.com> | 2007-03-23 16:35:57 +0000 |
|---|---|---|
| committer | Jeremy Dunck <jdunck@gmail.com> | 2007-03-23 16:35:57 +0000 |
| commit | fa3ed6e1341f7c8b468e2267b3fafddeb58cdac2 (patch) | |
| tree | 6d8bf65854f8431355e2d91cbc61a37ab6f23d9a /django/template | |
| parent | 8b279b63bef5c1348cc27c50633fc2d5ef09d7c1 (diff) | |
gis: Merged revisions 4669-4785 via svnmerge from trunk.
git-svn-id: http://code.djangoproject.com/svn/django/branches/gis@4786 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/template')
| -rw-r--r-- | django/template/__init__.py | 9 | ||||
| -rw-r--r-- | django/template/defaultfilters.py | 17 | ||||
| -rw-r--r-- | django/template/defaulttags.py | 53 |
3 files changed, 45 insertions, 34 deletions
diff --git a/django/template/__init__.py b/django/template/__init__.py index 678d19293c..0d8990a42b 100644 --- a/django/template/__init__.py +++ b/django/template/__init__.py @@ -91,6 +91,8 @@ UNKNOWN_SOURCE="<unknown source>" tag_re = re.compile('(%s.*?%s|%s.*?%s|%s.*?%s)' % (re.escape(BLOCK_TAG_START), re.escape(BLOCK_TAG_END), re.escape(VARIABLE_TAG_START), re.escape(VARIABLE_TAG_END), re.escape(COMMENT_TAG_START), re.escape(COMMENT_TAG_END))) +# matches if the string is valid number +number_re = re.compile(r'[-+]?(\d+|\d*\.\d+)$') # global dictionary of libraries that have been loaded using get_library libraries = {} @@ -632,12 +634,9 @@ def resolve_variable(path, context): (The example assumes VARIABLE_ATTRIBUTE_SEPARATOR is '.') """ - if path[0].isdigit(): + if number_re.match(path): number_type = '.' in path and float or int - try: - current = number_type(path) - except ValueError: - current = settings.TEMPLATE_STRING_IF_INVALID + current = number_type(path) elif path[0] in ('"', "'") and path[0] == path[-1]: current = path[1:-1] else: diff --git a/django/template/defaultfilters.py b/django/template/defaultfilters.py index b53375b42d..a025365c90 100644 --- a/django/template/defaultfilters.py +++ b/django/template/defaultfilters.py @@ -70,14 +70,15 @@ def floatformat(text, arg=-1): With a negative numeric argument, it will display that many decimal places -- but only if there's places to be displayed. Examples: - num1 = 34.23234 - num2 = 34.00000 - num1|floatformat results in 34.2 - num2|floatformat is 34 - num1|floatformat:3 is 34.232 - num2|floatformat:3 is 34.000 - num1|floatformat:-3 is 34.232 - num2|floatformat:-3 is 34 + + * num1 = 34.23234 + * num2 = 34.00000 + * num1|floatformat results in 34.2 + * num2|floatformat is 34 + * num1|floatformat:3 is 34.232 + * num2|floatformat:3 is 34.000 + * num1|floatformat:-3 is 34.232 + * num2|floatformat:-3 is 34 """ try: f = float(text) diff --git a/django/template/defaulttags.py b/django/template/defaulttags.py index 6aa53cfd8b..b18fa1dce7 100644 --- a/django/template/defaulttags.py +++ b/django/template/defaulttags.py @@ -435,6 +435,15 @@ def cycle(parser, token): cycle = register.tag(cycle) def debug(parser, token): + """ + Output a whole load of debugging information, including the current context and imported modules. + + Sample usage:: + + <pre> + {% debug %} + </pre> + """ return DebugNode() debug = register.tag(debug) @@ -538,21 +547,6 @@ def do_for(parser, token): do_for = register.tag("for", do_for) def do_ifequal(parser, token, negate): - """ - Output the contents of the block if the two arguments equal/don't equal each other. - - Examples:: - - {% ifequal user.id comment.user_id %} - ... - {% endifequal %} - - {% ifnotequal user.id comment.user_id %} - ... - {% else %} - ... - {% endifnotequal %} - """ bits = list(token.split_contents()) if len(bits) != 3: raise TemplateSyntaxError, "%r takes two arguments" % bits[0] @@ -568,11 +562,27 @@ def do_ifequal(parser, token, negate): #@register.tag def ifequal(parser, token): + """ + Output the contents of the block if the two arguments equal each other. + + Examples:: + + {% ifequal user.id comment.user_id %} + ... + {% endifequal %} + + {% ifnotequal user.id comment.user_id %} + ... + {% else %} + ... + {% endifnotequal %} + """ return do_ifequal(parser, token, False) ifequal = register.tag(ifequal) #@register.tag def ifnotequal(parser, token): + """Output the contents of the block if the two arguments are not equal. See ifequal.""" return do_ifequal(parser, token, True) ifnotequal = register.tag(ifnotequal) @@ -889,8 +899,9 @@ templatetag = register.tag(templatetag) def url(parser, token): """ - Returns an absolute URL matching given view with its parameters. This is a - way to define links that aren't tied to a particular url configuration: + Returns an absolute URL matching given view with its parameters. + + This is a way to define links that aren't tied to a particular URL configuration:: {% url path.to.some_view arg1,arg2,name1=value1 %} @@ -901,16 +912,16 @@ def url(parser, token): URL. All arguments for the URL should be present. For example if you have a view ``app_name.client`` taking client's id and - the corresponding line in a urlconf looks like this: + the corresponding line in a URLconf looks like this:: ('^client/(\d+)/$', 'app_name.client') - and this app's urlconf is included into the project's urlconf under some - path: + and this app's URLconf is included into the project's URLconf under some + path:: ('^clients/', include('project_name.app_name.urls')) - then in a template you can create a link for a certain client like this: + then in a template you can create a link for a certain client like this:: {% url app_name.client client.id %} |
