Commit 6a24eceb by Brian Wilson

decode utf-8 when reading html, and encode when writing.

parent 41b73e3b
...@@ -42,7 +42,7 @@ def render_to_string(template_name, dictionary, context=None, namespace='main'): ...@@ -42,7 +42,7 @@ def render_to_string(template_name, dictionary, context=None, namespace='main'):
context_dictionary.update(context) context_dictionary.update(context)
# fetch and render template # fetch and render template
template = middleware.lookup[namespace].get_template(template_name) template = middleware.lookup[namespace].get_template(template_name)
return template.render(**context_dictionary) return template.render_unicode(**context_dictionary)
def render_to_response(template_name, dictionary, context_instance=None, namespace='main', **kwargs): def render_to_response(template_name, dictionary, context_instance=None, namespace='main', **kwargs):
......
...@@ -54,5 +54,5 @@ class Template(MakoTemplate): ...@@ -54,5 +54,5 @@ class Template(MakoTemplate):
context_dictionary['MITX_ROOT_URL'] = settings.MITX_ROOT_URL context_dictionary['MITX_ROOT_URL'] = settings.MITX_ROOT_URL
context_dictionary['django_context'] = context_instance context_dictionary['django_context'] = context_instance
return super(Template, self).render(**context_dictionary) return super(Template, self).render_unicode(**context_dictionary)
...@@ -123,7 +123,7 @@ class HtmlDescriptor(XmlDescriptor, EditingDescriptor): ...@@ -123,7 +123,7 @@ class HtmlDescriptor(XmlDescriptor, EditingDescriptor):
try: try:
with system.resources_fs.open(filepath) as file: with system.resources_fs.open(filepath) as file:
html = file.read() html = file.read().decode('utf-8')
# Log a warning if we can't parse the file, but don't error # Log a warning if we can't parse the file, but don't error
if not check_html(html): if not check_html(html):
msg = "Couldn't parse html in {0}.".format(filepath) msg = "Couldn't parse html in {0}.".format(filepath)
...@@ -164,7 +164,7 @@ class HtmlDescriptor(XmlDescriptor, EditingDescriptor): ...@@ -164,7 +164,7 @@ class HtmlDescriptor(XmlDescriptor, EditingDescriptor):
resource_fs.makedir(os.path.dirname(filepath), allow_recreate=True) resource_fs.makedir(os.path.dirname(filepath), allow_recreate=True)
with resource_fs.open(filepath, 'w') as file: with resource_fs.open(filepath, 'w') as file:
file.write(self.definition['data']) file.write(self.definition['data'].encode('utf-8'))
# write out the relative name # write out the relative name
relname = path(pathname).basename() relname = path(pathname).basename()
......
...@@ -58,7 +58,7 @@ class CustomTagDescriptor(RawDescriptor): ...@@ -58,7 +58,7 @@ class CustomTagDescriptor(RawDescriptor):
params = dict(xmltree.items()) params = dict(xmltree.items())
with system.resources_fs.open('custom_tags/{name}' with system.resources_fs.open('custom_tags/{name}'
.format(name=template_name)) as template: .format(name=template_name)) as template:
return Template(template.read()).render(**params) return Template(template.read().decode('utf-8')).render(**params)
def __init__(self, system, definition, **kwargs): def __init__(self, system, definition, **kwargs):
......
...@@ -366,7 +366,7 @@ class XmlDescriptor(XModuleDescriptor): ...@@ -366,7 +366,7 @@ class XmlDescriptor(XModuleDescriptor):
filepath = self.__class__._format_filepath(self.category, url_path) filepath = self.__class__._format_filepath(self.category, url_path)
resource_fs.makedir(os.path.dirname(filepath), allow_recreate=True) resource_fs.makedir(os.path.dirname(filepath), allow_recreate=True)
with resource_fs.open(filepath, 'w') as file: with resource_fs.open(filepath, 'w') as file:
file.write(etree.tostring(xml_object, pretty_print=True)) file.write(etree.tostring(xml_object, pretty_print=True, encoding='utf-8', xml_declaration=True))
# And return just a pointer with the category and filename. # And return just a pointer with the category and filename.
record_object = etree.Element(self.category) record_object = etree.Element(self.category)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment