コード例 #1
0
 def _archive(self, notebook, format=u'json'):
   if notebook.archive == True:
     raise Exception("Cannot archive an archived copy of a notebook")
   archive = Notebook()
   archive.id = str(uuid.uuid4())
   archive.archive = True
   archive.for_notebook = notebook
   archive.name = notebook.name
   archive.content = notebook.content
   archive.save()
コード例 #2
0
 def new_notebook(self):
   """Create a new notebook and return its notebook_id."""
   n = Notebook()
   n.id = str(uuid.uuid4())
   n.name = 'New Notebook'
   metadata = current.new_metadata(name=n.name)
   nb = current.new_notebook(metadata=metadata)
   data = current.writes(nb, u'json')
   n.content = data
   n.save(force_insert=True)
   return n.id
コード例 #3
0
 def save_new_notebook(self, data, name=None, format=u'json'):
   """Save a new notebook and return its notebook_id."""
   if format != 'json':
     raise Exception('Only supporting JSON in Django backed notebook')
   n = Notebook()
   n.id = str(uuid.uuid4())
   if name != None:
     n.name = name
     nb = current.reads(data.decode('utf-8'), format)
     nb.metadata.name = name
     data = current.writes(nb, format)
   else:
     nb = current.reads(data.decode('utf-8'), format)
     n.name = nb.metadata.name
   n.content = data
   n.save(force_insert=True)
   self._archive(n)
   return n.id