diff --git a/IPython/html/nbconvert/handlers.py b/IPython/html/nbconvert/handlers.py index 40cca7f..b2317ee 100644 --- a/IPython/html/nbconvert/handlers.py +++ b/IPython/html/nbconvert/handlers.py @@ -6,6 +6,7 @@ import io import os import zipfile +import collections from tornado import web @@ -16,6 +17,7 @@ from ..base.handlers import ( from IPython.nbformat import from_dict from IPython.utils.py3compat import cast_bytes +from IPython.utils import text def find_resource_files(output_files_dir): files = [] @@ -87,9 +89,18 @@ class NbconvertFileHandler(IPythonHandler): raise web.HTTPError(400, "Not a notebook: %s" % path) self.set_header('Last-Modified', model['last_modified']) - + try: - output, resources = exporter.from_notebook_node(model['content']) + output, resources = exporter.from_notebook_node( + model['content'], + resources={ + "metadata": { + "name": name[:name.rfind('.')], + "modified_date": (model['last_modified'] + .strftime(text.date_format)) + } + } + ) except Exception as e: raise web.HTTPError(500, "nbconvert failed: %s" % e) diff --git a/IPython/nbconvert/exporters/exporter.py b/IPython/nbconvert/exporters/exporter.py index 38d9ce5..d81ac23 100644 --- a/IPython/nbconvert/exporters/exporter.py +++ b/IPython/nbconvert/exporters/exporter.py @@ -241,7 +241,9 @@ class Exporter(LoggingConfigurable): #Make sure the metadata extension exists in resources if 'metadata' in resources: if not isinstance(resources['metadata'], ResourcesDict): - resources['metadata'] = ResourcesDict(resources['metadata']) + new_metadata = ResourcesDict() + new_metadata.update(resources['metadata']) + resources['metadata'] = new_metadata else: resources['metadata'] = ResourcesDict() if not resources['metadata']['name']: