diff options
author | hardythe1 | 2014-03-12 18:08:22 +0530 |
---|---|---|
committer | hardythe1 | 2014-03-12 18:08:22 +0530 |
commit | c36488a3470b60a454005eda626f1d1f3af38f34 (patch) | |
tree | 1e38a74d263fda24cca3561c7e6c0f8ae5f344bd | |
parent | 142c9c81e0bc7357712a414b23958851fabb6801 (diff) | |
download | Python-TBC-Interface-c36488a3470b60a454005eda626f1d1f3af38f34.tar.gz Python-TBC-Interface-c36488a3470b60a454005eda626f1d1f3af38f34.tar.bz2 Python-TBC-Interface-c36488a3470b60a454005eda626f1d1f3af38f34.zip |
Adding view to use nbconvert directly
-rw-r--r-- | tbc/views.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/tbc/views.py b/tbc/views.py index ba13a21..194b73f 100644 --- a/tbc/views.py +++ b/tbc/views.py @@ -506,3 +506,25 @@ def BrowseBooks(request): context['items'] = book_images context['category'] = category return render_to_response('tbc/browse-books.html', context) + + +def ConvertNotebook(request, notebook_path=None): + path = os.path.abspath(os.path.dirname(__file__)) + path = path+"/static/uploads/" + path = path+notebook_path + notebook_name = path.split("/")[-1:] + notebook_name = notebook_name[0].split(".")[0] + path = path.split("/")[0:-1] + path = "/".join(path)+"/" + os.chdir(path) + try: + template = path.split("/")[8:] + template = "/".join(template)+notebook_name+".html" + print ("try") + return render_to_response(template, {}) + except: + os.popen("ipython nbconvert --to html "+path+notebook_name+".ipynb") + template = path.split("/")[8:] + template = "/".join(template)+notebook_name+".html" + print ("except") + return render_to_response(template, {}) |