from os import listdir, makedirs, path

from tornado.web import authenticated

from base import BaseHandler

class NotebookHandler(BaseHandler):
    @authenticated
    def get(self, notebook_name):
        notebook_name = self.encode_name(notebook_name)

        if not path.isdir(path.join(self.settings.repo, notebook_name)):
            self.redirect('/')
        else:
            if notebook_name.endswith('/'):
                notebook_name = notebook_name[:-1]
            notebook_path = path.join(self.settings.repo, notebook_name)
            notebook_contents = listdir(notebook_path)
            if '.git' in notebook_contents:
                notebook_contents.remove('.git')
            self.render('notebook.html', notebook_name=notebook_name,
                        note_name=None, notebook_contents=notebook_contents)

    @authenticated
    def post(self, notebook_name):
        notebook_name = self.encode_name(notebook_name)

        notebook_path = path.join(self.settings.repo, notebook_name)
        makedirs(notebook_path)
        self.finish()

@@ -183,32 +183,119 @@
 notebook_name):%0A
+        if notebook_name.endswith('/'):%0A            notebook_name = notebook_name%5B:-1%5D%0A
         notebook
@@ -326,32 +326,32 @@
 (notebook_name)%0A
-
 %0A        if not 
@@ -457,103 +457,8 @@
 se:%0A
-            if notebook_name.endswith('/'):%0A                notebook_name = notebook_name%5B:-1%5D%0A
     
@@ -868,32 +868,119 @@
 notebook_name):%0A
+        if notebook_name.endswith('/'):%0A            notebook_name = notebook_name%5B:-1%5D%0A
         notebook
@@ -1081,32 +1081,79 @@
  notebook_name)%0A
+        if not path.exists(notebook_path):%0A    
         makedirs

Fix notebook path and creation errors