Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0.5.3 Release #81

Merged
merged 5 commits into from
Feb 15, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fixed Content-Disposition header to correctly pass filenames with spa…
…ces. Resolves #77 #62.
  • Loading branch information
chris-kirby committed Feb 15, 2020
commit 6e622d6324a0d400140e779ffa7dc91174e2bacf
18 changes: 10 additions & 8 deletions hide_code/hide_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from .hide_code_config import HideCodeConfig as hc_config
from .utils import Utils


notebook_dir = []
base_url = ""

Expand All @@ -27,7 +28,7 @@ def get(self, *args):
exporter = HideCodeHTMLExporter()
output_html, resources = exporter.from_notebook_node(nb)
self.set_header('Content-Type', 'text/html')
self.set_header('Content-Disposition', 'attachment; filename=' + notebook_name(args) + '.html')
self.set_header('Content-Disposition', 'attachment; filename=' + notebook_name(args, 'html'))
self.flush()
self.write(output_html)
self.log.info("hide_code: Finished HTML export for {}".format(args[-1]))
Expand All @@ -43,7 +44,7 @@ def get(self, *args):
output_html, resources = exporter.from_notebook_node(nb)
output = pdfkit.from_string(output_html, False)
self.set_header('Content-Type', 'application/pdf')
self.set_header('Content-Disposition', 'attachment; filename=' + notebook_name(args) + '.pdf')
self.set_header('Content-Disposition', 'attachment; filename=' + notebook_name(args, 'pdf'))
self.flush()
self.write(output)
self.log.info("hide_code: Finished PDF export for {}".format(args[-1]))
Expand All @@ -57,7 +58,7 @@ def get(self, *args):
nb = nbformat.reads(f.read(), as_version=4)
exporter = HideCodePDFExporter()
output, resources = exporter.from_notebook_node(nb, resources={"metadata": {"name": notebook_name(args)}})
self.set_header('Content-Disposition', 'attachment; filename=' + notebook_name(args) + '.pdf')
self.set_header('Content-Disposition', 'attachment; filename=' + notebook_name(args, 'pdf'))
self.flush()
self.write(output)
self.log.info("hide_code: Finished Latex PDF export for {}".format(args[-1]))
Expand All @@ -71,7 +72,7 @@ def get(self, *args):
nb = nbformat.reads(f.read(), as_version=4)
exporter = HideCodeLatexExporter()
output, resources = exporter.from_notebook_node(nb, resources={"metadata": {"name": notebook_name(args)}})
self.set_header('Content-Disposition', 'attachment; filename=' + notebook_name(args) + '.tex')
self.set_header('Content-Disposition', 'attachment; filename=' + notebook_name(args, 'tex'))
self.flush()
self.write(output)
self.log.info("hide_code: Finished Latex export for {}".format(args[-1]))
Expand All @@ -85,7 +86,7 @@ def get(self, *args):
nb = nbformat.reads(f.read(), as_version=4)
exporter = HideCodeSlidesExporter()
output, resources = exporter.from_notebook_node(nb, resources={"metadata": {"name": notebook_name(args)}})
self.set_header('Content-Disposition', 'attachment; filename=' + notebook_name(args) + '.html')
self.set_header('Content-Disposition', 'attachment; filename=' + notebook_name(args, 'html'))
self.flush()
self.write(output)
self.log.info("hide_code: Finished Slides export for {}".format(args[-1]))
Expand Down Expand Up @@ -303,12 +304,13 @@ def route_pattern_for(exporter):
return url_path_join(base_url, 'notebooks/([^/]+)' + pattern, 'export', exporter)


def notebook_name(params):
def notebook_name(params, filetype):
"""
Returns notebook name without .ipynb extension.
Returns URL encoded notebook name without .ipynb extension.
"""
args = [param.replace('/', '') for param in params if param is not None]
return args[-1][:-6]
print(args)
return '"{}.{}"'.format(args[-1][:-6], filetype)


def ipynb_file_name(params):
Expand Down