Ticket #21046: 21046-1.diff

File 21046-1.diff, 1.8 KB (added by Claude Paroz, 10 years ago)
  • django/core/management/templates.py

    diff --git a/django/core/management/templates.py b/django/core/management/templates.py
    index d514c84..69514c4 100644
    a b from os import path  
    1414import django
    1515from django.template import Template, Context
    1616from django.utils import archive
     17from django.utils import six
    1718from django.utils.six.moves.urllib.request import urlretrieve
    1819from django.utils._os import rmtree_errorhandler
    1920from django.core.management.base import BaseCommand, CommandError
    class TemplateCommand(BaseCommand):  
    149150
    150151                # Only render the Python files, as we don't want to
    151152                # accidentally render Django templates files
    152                 with open(old_path, 'rb') as template_file:
    153                     content = template_file.read()
     153                render_file = False
    154154                if filename.endswith(extensions) or filename in extra_files:
    155                     content = content.decode('utf-8')
     155                    render_file = True
     156                with open(old_path, 'r%s' % ('' if render_file else 'b')) as template_file:
     157                    content = template_file.read()
     158                if render_file:
     159                    if six.PY2:
     160                        content = content.decode('utf-8')
    156161                    template = Template(content)
    157162                    content = template.render(context)
    158                     content = content.encode('utf-8')
    159                 with open(new_path, 'wb') as new_file:
     163                    if six.PY2:
     164                        content = content.encode('utf-8')
     165                with open(new_path, 'w%s' % ('' if render_file else 'b')) as new_file:
    160166                    new_file.write(content)
    161167
    162168                if self.verbosity >= 2:
Back to Top