Skip to content

Commit

Permalink
Accommodate Django 1.8's template system changes
Browse files Browse the repository at this point in the history
Django 1.8 introduces the possibility of using multiple template
engines, which means that some components of Django's template system
have been encapsulated in an Engine class instead of being available
globally, and other parts refactored and moved around.
  • Loading branch information
AlexHill committed Jan 21, 2015
1 parent fb92682 commit a50de50
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
13 changes: 11 additions & 2 deletions mezzanine/core/templatetags/mezzanine_tags.py
Expand Up @@ -14,10 +14,19 @@
from django.core.files import File
from django.core.files.storage import default_storage
from django.core.urlresolvers import reverse, resolve, NoReverseMatch
from django.template import (Context, Node, TextNode, Template,
TemplateSyntaxError, TOKEN_TEXT, TOKEN_VAR, TOKEN_COMMENT, TOKEN_BLOCK)
from django.db.models import Model
from django.db.models.loading import get_model
from django.template import Context, Node, Template, TemplateSyntaxError

try:
# Django >= 1.8
from django.template.base import (TOKEN_BLOCK, TOKEN_COMMENT,
TOKEN_TEXT, TOKEN_VAR, TextNode)
except ImportError:
# Django <= 1.7
from django.template import (TOKEN_BLOCK, TOKEN_COMMENT,
TOKEN_TEXT, TOKEN_VAR, TextNode)

from django.template.defaultfilters import escape
from django.template.loader import get_template
from django.utils import translation
Expand Down
5 changes: 3 additions & 2 deletions mezzanine/template/__init__.py
Expand Up @@ -110,15 +110,16 @@ def render(self, context):
else:
ts = templates_for_device(request, name)
t = select_template(ts)
self.nodelist = t.nodelist

self.template = t
parts = [template.Variable(part).resolve(context)
for part in token.split_contents()[1:]]
if takes_context:
parts.insert(0, context)
result = tag_func(*parts)
autoescape = context.autoescape
context = context_class(result, autoescape=autoescape)
return self.nodelist.render(context)
return self.template.render(context)

return InclusionTagNode()
return self.tag(tag_wrapper)
Expand Down
17 changes: 15 additions & 2 deletions mezzanine/template/loader_tags.py
Expand Up @@ -5,7 +5,6 @@

from django.template import Template, TemplateSyntaxError, TemplateDoesNotExist
from django.template.loader_tags import ExtendsNode
from django.template.loader import find_template_loader

from mezzanine import template

Expand Down Expand Up @@ -47,7 +46,21 @@ def find_template(self, name, context, peeking=False):

# These imports want settings, which aren't available when this
# module is imported to ``add_to_builtins``, so do them here.
from django.template.loaders.app_directories import app_template_dirs
import django.template.loaders.app_directories as app_directories
try:
# Django >= 1.8
app_template_dirs = app_directories.get_app_template_dirs
except AttributeError:
# Django <= 1.7
app_template_dirs = app_directories.app_template_dirs

try:
# Django >= 1.8
find_template_loader = context.engine.find_template_loader
except AttributeError:
# Django <= 1.7
from django.template.loaders import find_template_loader

from mezzanine.conf import settings

# Store a dictionary in the template context mapping template
Expand Down

0 comments on commit a50de50

Please sign in to comment.