Re: [Django] #14169: Improve TemplateSyntaxError for invalid block tags

2010-12-03 Thread Django
#14169: Improve TemplateSyntaxError for invalid block tags
--+-
  Reporter:  filipd   | Owner:  nobody  

Status:  closed   | Milestone:  

 Component:  Template system  |   Version:  SVN 

Resolution:  wontfix  |  Keywords:  TemplateSyntaxError, 
exception value
 Stage:  Unreviewed   | Has_patch:  0   

Needs_docs:  0|   Needs_tests:  0   

Needs_better_patch:  0|  
--+-
Changes (by mariarchi):

  * status:  new => closed
  * resolution:  => wontfix

Comment:

 I don't really think it's feasible either

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



Re: [Django] #14169: Improve TemplateSyntaxError for invalid block tags

2010-10-05 Thread Django
#14169: Improve TemplateSyntaxError for invalid block tags
--+-
  Reporter:  filipd   | Owner:  nobody  

Status:  new  | Milestone:  

 Component:  Template system  |   Version:  SVN 

Resolution:   |  Keywords:  TemplateSyntaxError, 
exception value
 Stage:  Unreviewed   | Has_patch:  0   

Needs_docs:  0|   Needs_tests:  0   

Needs_better_patch:  0|  
--+-
Changes (by mk):

  * needs_better_patch:  => 0
  * needs_tests:  => 0
  * needs_docs:  => 0

Comment:

 This is hard to do, next to impossible even with the current code base.

 In django.template.Parser.invalid_block_tag, we can determine which tags
 are allowed using self.tags. However, this dict only contains f.e.
 'block', not 'endblock', only 'blocktrans', not 'endblocktrans'. We have
 no way of knowing whether 'endblock' or 'endblocktrans' are valid tags
 because the template tag author can freely choose tag names as he/she
 wants. It gets even worse with {% plural %} inside a blocktrans-block...

 Here's my stupid attempt at a patch, if anyone wants to continue:

 {{{
 diff --git a/django/template/__init__.py b/django/template/__init__.py
 index c316786..de460d0 100644
 --- a/django/template/__init__.py
 +++ b/django/template/__init__.py
 @@ -330,6 +330,8 @@ class Parser(object):

  def invalid_block_tag(self, token, command, parse_until=None):
  if parse_until:
 +if command not in self.tags:
 +raise self.error(token, "Invalid block tag: '%s', did you
 forget to load it?" % command)
  raise self.error(token, "Invalid block tag: '%s', expected
 %s" % (command, get_text_list(["'%s'" % p for p in parse_until])))
  raise self.error(token, "Invalid block tag: '%s'" % command)

 diff --git a/tests/regressiontests/templates/tests.py
 b/tests/regressiontests/templates/tests.py
 index 9e2d175..3ca8bf8 100644
 --- a/tests/regressiontests/templates/tests.py
 +++ b/tests/regressiontests/templates/tests.py
 @@ -318,6 +318,16 @@ class Templates(unittest.TestCase):
  except TemplateSyntaxError, e:
  self.assertEquals(e.args[0], "Invalid block tag: 'endblock',
 expected 'else' or 'endif'")

 +try:
 +t = Template("{% if 1 %}lala{% anything 'something' %}{%
 endif %}")
 +except TemplateSyntaxError, e:
 +self.assertEquals(e.args[0], "Invalid block tag: 'anything',
 did you forget to load it?")
 +
 +try:
 +t = Template("{% load i18n %}{% if 1 %}lala{% trans
 'something' %}{% bla %}{% endif %}")
 +except TemplateSyntaxError, e:
 +self.assertEquals(e.args[0], "Invalid block tag: 'bla',
 expected 'else' or 'endif'")
 +
  def test_templates(self):
  template_tests = self.get_template_tests()
  filter_tests = filters.get_filter_tests()
 }}}

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



[Django] #14169: Improve TemplateSyntaxError for invalid block tags

2010-08-25 Thread Django
#14169: Improve TemplateSyntaxError for invalid block tags
--+-
 Reporter:  filipd|   Owner:  nobody
   Status:  new   |   Milestone:
Component:  Template system   | Version:  SVN   
 Keywords:  TemplateSyntaxError, exception value  |   Stage:  Unreviewed
Has_patch:  0 |  
--+-
 some_template.html:

 {% block someblock %}{% endblock %}

 some_other_template.html:

 {% extends 'some_template.html' %}
 {% block someblock %}
{% blocktrans %}
   Hello world!
{% endblocktrans%}
 {% endlbock %}

 Django raises a TemplateSyntaxError with an exception value "Invalid block
 tag: 'blocktrans', expected 'endblock' or 'endblock someblock'. Because I
 didn't take my morning coffee, this put me way off thinking since when was
 {% blocktrans %} an invalid node for {% block %}? 20 minutes later, after
 reverting from trunk to the v1.2 tag, I've just figured I've never loaded
 the {% blocktrans %} tag in the first place. Could this particular
 instance of TemplateSyntaxError be expanded to perform an additional check
 to see if `sometag` is actually loaded.

 This would seem a more appropriate exception value:

 Invalid block tag: 'blocktrans'

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.