cf9cb06
From c8495264b503a595fbc89e6c8a83a402eff445c6 Mon Sep 17 00:00:00 2001
cf9cb06
From: Mathieu Pillard <m@virgule.net>
cf9cb06
Date: Sun, 25 May 2014 14:09:33 +0200
cf9cb06
Subject: [PATCH] Use get_template() when dealing with django templates
cf9cb06
cf9cb06
---
cf9cb06
 compressor/offline/django.py | 16 +++++++---------
cf9cb06
 1 file changed, 7 insertions(+), 9 deletions(-)
cf9cb06
cf9cb06
diff --git a/compressor/offline/django.py b/compressor/offline/django.py
cf9cb06
index 6541471..3986562 100644
cf9cb06
--- a/compressor/offline/django.py
cf9cb06
+++ b/compressor/offline/django.py
cf9cb06
@@ -1,13 +1,12 @@
cf9cb06
 from __future__ import absolute_import
cf9cb06
-import io
cf9cb06
 from copy import copy
cf9cb06
 
cf9cb06
 from django import template
cf9cb06
 from django.conf import settings
cf9cb06
-from django.template import Template
cf9cb06
 from django.template import Context
cf9cb06
 from django.template.base import Node, VariableNode, TextNode, NodeList
cf9cb06
 from django.template.defaulttags import IfNode
cf9cb06
+from django.template.loader import get_template
cf9cb06
 from django.template.loader_tags import ExtendsNode, BlockNode, BlockContext
cf9cb06
 
cf9cb06
 
cf9cb06
@@ -93,13 +92,12 @@ def __init__(self, charset):
cf9cb06
         self.charset = charset
cf9cb06
 
cf9cb06
     def parse(self, template_name):
cf9cb06
-        with io.open(template_name, mode='rb') as file:
cf9cb06
-            try:
cf9cb06
-                return Template(file.read().decode(self.charset))
cf9cb06
-            except template.TemplateSyntaxError as e:
cf9cb06
-                raise TemplateSyntaxError(str(e))
cf9cb06
-            except template.TemplateDoesNotExist as e:
cf9cb06
-                raise TemplateDoesNotExist(str(e))
cf9cb06
+        try:
cf9cb06
+            return get_template(template_name)
cf9cb06
+        except template.TemplateSyntaxError as e:
cf9cb06
+            raise TemplateSyntaxError(str(e))
cf9cb06
+        except template.TemplateDoesNotExist as e:
cf9cb06
+            raise TemplateDoesNotExist(str(e))
cf9cb06
 
cf9cb06
     def process_template(self, template, context):
cf9cb06
         return True