Ticket #8116: 8116.2.diff

File 8116.2.diff, 4.7 KB (added by Rob Hudson, 13 years ago)

Updated to work with 1.3alpha1. Now with passing tests.

  • django/template/__init__.py

    diff --git a/django/template/__init__.py b/django/template/__init__.py
    index ca1bd49..adf0352 100644
    a b from django.template.base import (ALLOWED_VARIABLE_CHARS, BLOCK_TAG_END,  
    5959
    6060# Exceptions
    6161from django.template.base import (ContextPopException, InvalidTemplateLibrary,
    62     TemplateDoesNotExist, TemplateEncodingError, TemplateSyntaxError,
    63     VariableDoesNotExist)
     62    TemplateDoesNotExist, IncludedTemplateDoesNotExist, TemplateEncodingError,
     63    TemplateSyntaxError, VariableDoesNotExist)
    6464
    6565# Template parts
    6666from django.template.base import (Context, FilterExpression, Lexer, Node,
  • django/template/base.py

    diff --git a/django/template/base.py b/django/template/base.py
    index d934e05..063b5db 100644
    a b class TemplateSyntaxError(Exception):  
    6161class TemplateDoesNotExist(Exception):
    6262    pass
    6363
     64class IncludedTemplateDoesNotExist(Exception):
     65    pass
     66
    6467class TemplateEncodingError(Exception):
    6568    pass
    6669
  • django/template/loader.py

    diff --git a/django/template/loader.py b/django/template/loader.py
    index 279d8e8..885cd16 100644
    a b  
    2626# installed, because pkg_resources is necessary to read eggs.
    2727
    2828from django.core.exceptions import ImproperlyConfigured
    29 from django.template.base import Origin, Template, Context, TemplateDoesNotExist, add_to_builtins
     29from django.template.base import (Origin, Template, Context,
     30                                  TemplateDoesNotExist,
     31                                  IncludedTemplateDoesNotExist,
     32                                  add_to_builtins)
    3033from django.utils.importlib import import_module
    3134from django.conf import settings
    3235
    def get_template(template_name):  
    157160    template, origin = find_template(template_name)
    158161    if not hasattr(template, 'render'):
    159162        # template needs to be compiled
    160         template = get_template_from_string(template, origin, template_name)
     163        try:
     164            template = get_template_from_string(template, origin, template_name)
     165        except TemplateDoesNotExist, included_template_name:
     166            raise IncludedTemplateDoesNotExist, included_template_name
    161167    return template
    162168
    163169def get_template_from_string(source, origin=None, name=None):
    def select_template(template_name_list):  
    190196    for template_name in template_name_list:
    191197        try:
    192198            return get_template(template_name)
    193         except TemplateDoesNotExist:
     199        except TemplateDoesNotExist, e:
     200            if isinstance(e, IncludedTemplateDoesNotExist):
     201                raise
    194202            continue
    195203    # If we get here, none of the templates could be loaded
    196204    raise TemplateDoesNotExist(', '.join(template_name_list))
  • tests/regressiontests/templates/tests.py

    diff --git a/tests/regressiontests/templates/tests.py b/tests/regressiontests/templates/tests.py
    index 475f923..6194f46 100644
    a b class Templates(unittest.TestCase):  
    248248                r = tmpl.render(template.Context({}))
    249249            except template.TemplateSyntaxError, e:
    250250                settings.TEMPLATE_DEBUG = old_td
    251                 self.assertEqual(e.args[0], 'Caught TemplateDoesNotExist while rendering: missing.html')
     251                self.assertEqual(e.args[0], 'Caught IncludedTemplateDoesNotExist while rendering: missing.html')
    252252            self.assertEqual(r, None, 'Template rendering unexpectedly succeeded, produced: ->%r<-' % r)
    253253        finally:
    254254            loader.template_source_loaders = old_loaders
    class Templates(unittest.TestCase):  
    274274            try:
    275275                r = tmpl.render(template.Context({}))
    276276            except template.TemplateSyntaxError, e:
    277                 self.assertEqual(e.args[0], 'Caught TemplateDoesNotExist while rendering: missing.html')
     277                self.assertEqual(e.args[0], 'Caught IncludedTemplateDoesNotExist while rendering: missing.html')
    278278            self.assertEqual(r, None, 'Template rendering unexpectedly succeeded, produced: ->%r<-' % r)
    279279
    280280            # For the cached loader, repeat the test, to ensure the first attempt did not cache a
    class Templates(unittest.TestCase):  
    283283            try:
    284284                tmpl.render(template.Context({}))
    285285            except template.TemplateSyntaxError, e:
    286                 self.assertEqual(e.args[0], 'Caught TemplateDoesNotExist while rendering: missing.html')
     286                self.assertEqual(e.args[0], 'Caught IncludedTemplateDoesNotExist while rendering: missing.html')
    287287            self.assertEqual(r, None, 'Template rendering unexpectedly succeeded, produced: ->%r<-' % r)
    288288        finally:
    289289            loader.template_source_loaders = old_loaders
Back to Top