From 08f032f6b5e4e0ef6fcec59c687055e38cbe7561 Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Sun, 15 Jan 2006 00:53:19 +0000 Subject: [PATCH] magic-removal: Merged to [1964] git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@1965 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/contrib/admin/media/css/global.css | 2 +- django/template/__init__.py | 11 +++++++++-- django/template/defaulttags.py | 3 +-- docs/tutorial01.txt | 4 ++++ tests/othertests/templates.py | 9 +++++++-- 5 files changed, 22 insertions(+), 7 deletions(-) diff --git a/django/contrib/admin/media/css/global.css b/django/contrib/admin/media/css/global.css index 454ac29010..91ee03dd85 100644 --- a/django/contrib/admin/media/css/global.css +++ b/django/contrib/admin/media/css/global.css @@ -3,7 +3,7 @@ by Wilson Miner (wminer@ljworld.com). Copyright 2004-2005 Lawrence Journal-World */ -body { margin:0; padding:0; font-family:"Lucida Grande","Bitstream Vera Sans",Verdana,Arial,sans-serif; color:#333; } +body { margin:0; padding:0; font-family:"Lucida Grande","Bitstream Vera Sans",Verdana,Arial,sans-serif; color:#333; background:#fff; } /* LINKS */ a:link, a:visited { color: #5b80b2; text-decoration:none; } diff --git a/django/template/__init__.py b/django/template/__init__.py index 4fbc19a873..d87653c21c 100644 --- a/django/template/__init__.py +++ b/django/template/__init__.py @@ -257,6 +257,13 @@ class Parser(object): self.unclosed_block_tag(parse_until) return nodelist + def skip_past(self, endtag): + while self.tokens: + token = self.next_token() + if token.token_type == TOKEN_BLOCK and token.contents == endtag: + return + self.unclosed_block_tag([endtag]) + def create_variable_node(self, filter_expression): return VariableNode(filter_expression) @@ -363,8 +370,8 @@ def parser_factory(*args, **kwargs): return DebugParser(*args, **kwargs) else: return Parser(*args, **kwargs) - - + + class TokenParser: """ Subclass this and implement the top() method to parse a template line. When diff --git a/django/template/defaulttags.py b/django/template/defaulttags.py index 956d736c46..72669d6af1 100644 --- a/django/template/defaulttags.py +++ b/django/template/defaulttags.py @@ -286,8 +286,7 @@ def comment(parser, token): """ Ignore everything between ``{% comment %}`` and ``{% endcomment %}`` """ - nodelist = parser.parse(('endcomment',)) - parser.delete_first_token() + parser.skip_past('endcomment') return CommentNode() comment = register.tag(comment) diff --git a/docs/tutorial01.txt b/docs/tutorial01.txt index 004c3ba61d..67b4053ef5 100644 --- a/docs/tutorial01.txt +++ b/docs/tutorial01.txt @@ -455,8 +455,12 @@ Let's jump back into the Python interactive shell by running What's up? >>> polls.get_object(question__startswith='What') What's up? + + # Get the poll whose year is 2005. Of course, if you're going through this + # tutorial in another year, change as appropriate. >>> polls.get_object(pub_date__year=2005) What's up? + >>> polls.get_object(id__exact=2) Traceback (most recent call last): ... diff --git a/tests/othertests/templates.py b/tests/othertests/templates.py index 8af8e027cf..e1f6bd9c0a 100644 --- a/tests/othertests/templates.py +++ b/tests/othertests/templates.py @@ -156,6 +156,11 @@ TEMPLATE_TESTS = { 'comment-tag01': ("{% comment %}this is hidden{% endcomment %}hello", {}, "hello"), 'comment-tag02': ("{% comment %}this is hidden{% endcomment %}hello{% comment %}foo{% endcomment %}", {}, "hello"), + # Comment tag can contain invalid stuff. + 'comment-tag03': ("foo{% comment %} {% if %} {% endcomment %}", {}, "foo"), + 'comment-tag04': ("foo{% comment %} {% endblock %} {% endcomment %}", {}, "foo"), + 'comment-tag05': ("foo{% comment %} {% somerandomtag %} {% endcomment %}", {}, "foo"), + ### CYCLE TAG ############################################################# #'cycleXX': ('', {}, ''), 'cycle01': ('{% cycle a, %}', {}, 'a'), @@ -440,7 +445,7 @@ def run_tests(verbosity=0, standalone=False): failed_tests = [] tests = TEMPLATE_TESTS.items() tests.sort() - + # Turn TEMPLATE_DEBUG off, because tests assume that. old_td, settings.TEMPLATE_DEBUG = settings.TEMPLATE_DEBUG, False for name, vals in tests: @@ -473,7 +478,7 @@ def run_tests(verbosity=0, standalone=False): loader.template_source_loaders = old_template_loaders deactivate() settings.TEMPLATE_DEBUG = old_td - + if failed_tests and not standalone: msg = "Template tests %s failed." % failed_tests if not verbosity: