From e2786e0fcab92b95a5a041003ab2b4693f7f9050 Mon Sep 17 00:00:00 2001 From: Mahesh Gudi Date: Mon, 29 Feb 2016 12:57:07 +0530 Subject: Update views.py made the necessary changes in the convert notebook function--- tbc/views.py | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'tbc/views.py') diff --git a/tbc/views.py b/tbc/views.py index 19c9b3b..e66947c 100755 --- a/tbc/views.py +++ b/tbc/views.py @@ -1197,20 +1197,19 @@ def ConvertNotebook(request, notebook_path=None): 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" + template = path+notebook_name+".html" + notebook_html = str(path+notebook_name+".html") + notebook_ipynb =str(path+notebook_name+".ipynb") + changed_time = float(os.stat(path+notebook_name+".html").st_mtime) + modified_time = float(os.stat(path+notebook_name+".ipynb").st_mtime) + + if os.path.isfile(notebook_html) and changed_time > modified_time: + template = notebook_html + return render_to_response(template, {}) + else: + notebook_convert = "ipython nbconvert --to html %s" % str(notebook_ipynb) + subprocess.call (notebook_convert) + template = notebook_html return render_to_response(template, {}) -- cgit From 661f6b08e6c131e81e3051a549b09c0cacdfff7e Mon Sep 17 00:00:00 2001 From: Mahesh Gudi Date: Tue, 1 Mar 2016 18:16:55 +0530 Subject: Update views.py made the necessary changes as suggested by Ankit--- tbc/views.py | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) (limited to 'tbc/views.py') diff --git a/tbc/views.py b/tbc/views.py index e66947c..6ab269d 100755 --- a/tbc/views.py +++ b/tbc/views.py @@ -1191,26 +1191,19 @@ def BrowseBooks(request): def ConvertNotebook(request, notebook_path=None): 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)+"/" - template = path+notebook_name+".html" - notebook_html = str(path+notebook_name+".html") - notebook_ipynb =str(path+notebook_name+".ipynb") - changed_time = float(os.stat(path+notebook_name+".html").st_mtime) - modified_time = float(os.stat(path+notebook_name+".ipynb").st_mtime) - - if os.path.isfile(notebook_html) and changed_time > modified_time: - template = notebook_html - return render_to_response(template, {}) + path = os.path.join(local.path, notebook_path.strip(".ipynb")) + template_html = path+".html" + template_ipynb =path+".ipynb" + changed_time = float(os.stat(template_html).st_mtime) + modified_time = float(os.stat(template_ipynb).st_mtime) + + if os.path.isfile(template_html) and changed_time > modified_time: + return render_to_response(template_html, {}) else: - notebook_convert = "ipython nbconvert --to html %s" % str(notebook_ipynb) + notebook_convert = "ipython nbconvert --to html %s" % str(template_ipynb) subprocess.call (notebook_convert) - template = notebook_html - return render_to_response(template, {}) + return render_to_response(template_html, {}) + def CompletedBooks(request): -- cgit From 102cd2a7b90732eb293a7621b0570a080cd4320b Mon Sep 17 00:00:00 2001 From: Mahesh Gudi Date: Mon, 7 Mar 2016 16:01:08 +0530 Subject: Update views.py --- tbc/views.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'tbc/views.py') diff --git a/tbc/views.py b/tbc/views.py index 6ab269d..9e3a2e7 100755 --- a/tbc/views.py +++ b/tbc/views.py @@ -1190,14 +1190,17 @@ 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 = os.path.join(local.path, notebook_path.strip(".ipynb")) template_html = path+".html" template_ipynb =path+".ipynb" - changed_time = float(os.stat(template_html).st_mtime) - modified_time = float(os.stat(template_ipynb).st_mtime) + 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 changed_time > modified_time: + 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) -- cgit