Permalink
Browse files

File upload/import working from notebook browser.

  • Loading branch information...
1 parent b0243db commit 53c7ec7497b11133bf270668219aedc996429e94 @ellisonbg ellisonbg committed Aug 6, 2011
@@ -89,8 +89,9 @@ def post(self):
nbm = self.application.notebook_manager
body = self.request.body.strip()
format = self.get_argument('format', default='json')
+ name = self.get_argument('name', default=None)
if body:
- notebook_id = nbm.save_new_notebook(body, format)
+ notebook_id = nbm.save_new_notebook(body, name=name, format=format)
else:
notebook_id = nbm.new_notebook()
self.set_header('Location', '/'+notebook_id)
@@ -120,7 +121,8 @@ def get(self, notebook_id):
def put(self, notebook_id):
nbm = self.application.notebook_manager
format = self.get_argument('format', default='json')
- nbm.save_notebook(notebook_id, self.request.body, format)
+ name = self.get_argument('name', default=None)
+ nbm.save_notebook(notebook_id, self.request.body, name=name, format=format)
self.set_status(204)
self.finish()
@@ -124,30 +124,57 @@ def get_notebook_object(self, notebook_id):
raise web.HTTPError(404)
return last_modified, nb
- def save_new_notebook(self, data, format=u'json'):
- """Save a new notebook and return its notebook_id."""
+ def save_new_notebook(self, data, name=None, format=u'json'):
+ """Save a new notebook and return its notebook_id.
+
+ If a name is passed in, it overrides any values in the notebook data
+ and the value in the data is updated to use that value.
+ """
if format not in self.allowed_formats:
raise web.HTTPError(415)
+
try:
nb = current.reads(data, format)
except:
- raise web.HTTPError(400)
- try:
- name = nb.name
- except AttributeError:
- raise web.HTTPError(400)
+ if format == u'xml':
+ # v1 notebooks might come in with a format='xml' but be json.
+ try:
+ nb = current.reads(data, u'json')
+ except:
+ raise web.HTTPError(400)
+ else:
+ raise web.HTTPError(400)
+
+ if name is None:
+ try:
+ name = nb.name
+ except AttributeError:
+ raise web.HTTPError(400)
+ nb.name = name
+
notebook_id = self.new_notebook_id(name)
self.save_notebook_object(notebook_id, nb)
return notebook_id
- def save_notebook(self, notebook_id, data, format=u'json'):
+ def save_notebook(self, notebook_id, data, name=None, format=u'json'):
"""Save an existing notebook by notebook_id."""
if format not in self.allowed_formats:
raise web.HTTPError(415)
+
try:
nb = current.reads(data, format)
except:
- raise web.HTTPError(400)
+ if format == u'xml':
+ # v1 notebooks might come in with a format='xml' but be json.
+ try:
+ nb = current.reads(data, u'json')
+ except:
+ raise web.HTTPError(400)
+ else:
+ raise web.HTTPError(400)
+
+ if name is not None:
+ nb.name = name
self.save_notebook_object(notebook_id, nb)
def save_notebook_object(self, notebook_id, nb):
@@ -18,12 +18,22 @@ body {
overflow: auto;
}
+#left_panel {
+}
+
+#drop_zone {
+ height: 200px;
+ width: 200px
+}
+
#content_panel {
width: 600px;
}
#content_toolbar {
- padding: 10px 5px;
+ padding: 10px 5px 5px 5px;
+ height: 25px;
+ line-height: 25px;
}
#header_border {
@@ -35,6 +45,10 @@ body {
width: 100%;
}
+#drag_info {
+ float: left;
+}
+
#notebooks_buttons {
float: right;
}
@@ -59,6 +73,10 @@ body {
float: right;
}
+.item_buttons .upload_button {
+ color: darkred;
+}
+
.highlight_text {
color: blue;
}
@@ -10,14 +10,17 @@ $(document).ready(function () {
$('div#header_border').addClass('border-box-sizing ui-widget ui-widget-content');
$('div#main_app').addClass('border-box-sizing ui-widget');
- $('div#app_hbox').addClass('hbox center');
+ $('div#app_hbox').addClass('hbox');
$('div#content_toolbar').addClass('ui-widget ui-helper-clearfix');
- $('#new_notebook').click(function (e) {
+ $('#new_notebook').button().click(function (e) {
window.open('/new');
});
+ $('div#left_panel').addClass('box-flex');
+ $('div#right_panel').addClass('box-flex');
+
IPython.notebook_list = new IPython.NotebookList('div#notebook_list');
IPython.notebook_list.load_list();
Oops, something went wrong.

0 comments on commit 53c7ec7

Please sign in to comment.