diff options
author | King | 2016-03-30 15:36:51 +0530 |
---|---|---|
committer | King | 2016-03-30 15:36:51 +0530 |
commit | 8876df52d088a1de0ea769a46b82ad6fb0682a80 (patch) | |
tree | c14117e676de00389fe6797a4eef147e46d1c5bd /tbc | |
parent | 9e405686f5e27fbc4ee227cad87223456ae9f703 (diff) | |
parent | 102cd2a7b90732eb293a7621b0570a080cd4320b (diff) | |
download | Python-TBC-Interface-8876df52d088a1de0ea769a46b82ad6fb0682a80.tar.gz Python-TBC-Interface-8876df52d088a1de0ea769a46b82ad6fb0682a80.tar.bz2 Python-TBC-Interface-8876df52d088a1de0ea769a46b82ad6fb0682a80.zip |
Merge pull request #25 from FOSSEE/maheshgudi-patch-convert-notebook
Update views.py
Diffstat (limited to 'tbc')
-rwxr-xr-x | tbc/views.py | 37 |
1 files changed, 16 insertions, 21 deletions
diff --git a/tbc/views.py b/tbc/views.py index 19c9b3b..9e3a2e7 100755 --- a/tbc/views.py +++ b/tbc/views.py @@ -1190,28 +1190,23 @@ def BrowseBooks(request): def ConvertNotebook(request, notebook_path=None): + """ Checks for the modified time of ipython notebooks and corresponding html page and replaces html page with + new one if corresponding ipython notebook has been modified. """ + context = {} - path = local.path - 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: - changed_time = time.ctime(os.path.getctime(path+notebook_name+".html")) - modified_time = time.ctime(os.path.getctime(path+notebook_name+".ipynb")) - if(changed_time > modified_time): - template = path+notebook_name+".html" - return render_to_response(template, {}) - else: - os.popen("ipython nbconvert --to html \""+path+notebook_name+".ipynb\"") - template = path+notebook_name+".html" - return render_to_response(template, {}) - except: - os.popen("ipython nbconvert --to html \""+path+notebook_name+".ipynb\"") - template = path+notebook_name+".html" - return render_to_response(template, {}) + path = os.path.join(local.path, notebook_path.strip(".ipynb")) + template_html = path+".html" + template_ipynb =path+".ipynb" + modified_time_for_html = os.stat(template_html).st_mtime + modified_time_for_ipynb = os.stat(template_ipynb).st_mtime + + if os.path.isfile(template_html) and modified_time_for_html > modified_time_for_ipynb: + return render_to_response(template_html, {}) + else: + notebook_convert = "ipython nbconvert --to html %s" % str(template_ipynb) + subprocess.call (notebook_convert) + return render_to_response(template_html, {}) + def CompletedBooks(request): |