controller.Notebooks.save_note() now looks for the note to be saved in that
notebook's trash. If found, it first undeletes the note before saving it. This is necessary if, for instance, you have the same note open in window A and window B, and then you delete the note in window A and subsequently modify it and save it in window B.
This commit is contained in:
parent
20313728d2
commit
4887defa83
|
@ -313,22 +313,40 @@ class Notebooks( object ):
|
|||
self.__database.load( note_id, self.__scheduler.thread )
|
||||
note = ( yield Scheduler.SLEEP )
|
||||
|
||||
# if the note is already in the database, load it and update it
|
||||
if note and note in notebook.notes:
|
||||
# check whether the provided note contents have been changed since the previous revision
|
||||
self.__database.load( note_id, self.__scheduler.thread, previous_revision )
|
||||
old_note = ( yield Scheduler.SLEEP )
|
||||
|
||||
# check whether the provided note contents have been changed since the previous revision
|
||||
def update_note( current_notebook, old_note ):
|
||||
# the note hasn't been changed, so bail without updating it
|
||||
if contents == old_note.contents:
|
||||
previous_revision = note.revision
|
||||
new_revision = None
|
||||
# the note has changed, so update it
|
||||
else:
|
||||
previous_revision = note.revision
|
||||
notebook.update_note( note, contents )
|
||||
new_revision = note.revision
|
||||
# the note is not already in the database, so create it
|
||||
|
||||
return new_revision
|
||||
|
||||
# if the note is already in the given notebook, load it and update it
|
||||
if note and note in notebook.notes:
|
||||
self.__database.load( note_id, self.__scheduler.thread, previous_revision )
|
||||
old_note = ( yield Scheduler.SLEEP )
|
||||
|
||||
previous_revision = note.revision
|
||||
new_revision = update_note( notebook, old_note )
|
||||
|
||||
# the note is not already in the given notebook, so look for it in the trash
|
||||
elif note and notebook.trash and note in notebook.trash.notes:
|
||||
self.__database.load( note_id, self.__scheduler.thread, previous_revision )
|
||||
old_note = ( yield Scheduler.SLEEP )
|
||||
|
||||
# undelete the note, putting it back in the given notebook
|
||||
previous_revision = note.revision
|
||||
notebook.trash.remove_note( note )
|
||||
note.deleted_from = None
|
||||
notebook.add_note( note )
|
||||
|
||||
new_revision = update_note( notebook, old_note )
|
||||
|
||||
# otherwise, create a new note
|
||||
else:
|
||||
previous_revision = None
|
||||
note = Note( note_id, contents )
|
||||
|
|
|
@ -302,7 +302,7 @@ class Test_notebooks( Test_controller ):
|
|||
def test_save_note( self, startup = False ):
|
||||
self.login()
|
||||
|
||||
# save over an existing note supplying new contents and a new title
|
||||
# save over an existing note, supplying new contents and a new title
|
||||
previous_revision = self.note.revision
|
||||
new_note_contents = u"<h3>new title</h3>new blah"
|
||||
result = self.http_post( "/notebooks/save_note/", dict(
|
||||
|
@ -361,10 +361,70 @@ class Test_notebooks( Test_controller ):
|
|||
def test_save_startup_note_without_login( self ):
|
||||
self.test_save_note_without_login( startup = True )
|
||||
|
||||
def test_save_deleted_note( self ):
|
||||
self.login()
|
||||
|
||||
result = self.http_post( "/notebooks/delete_note/", dict(
|
||||
notebook_id = self.notebook.object_id,
|
||||
note_id = self.note.object_id,
|
||||
), session_id = self.session_id )
|
||||
|
||||
# save over a deleted note, supplying new contents and a new title. this should cause the note
|
||||
# to be automatically undeleted
|
||||
previous_revision = self.note.revision
|
||||
new_note_contents = u"<h3>new title</h3>new blah"
|
||||
result = self.http_post( "/notebooks/save_note/", dict(
|
||||
notebook_id = self.notebook.object_id,
|
||||
note_id = self.note.object_id,
|
||||
contents = new_note_contents,
|
||||
startup = False,
|
||||
previous_revision = previous_revision,
|
||||
), session_id = self.session_id )
|
||||
|
||||
assert result[ "new_revision" ] and result[ "new_revision" ] != previous_revision
|
||||
assert result[ "previous_revision" ] == previous_revision
|
||||
|
||||
# make sure the old title can no longer be loaded
|
||||
result = self.http_post( "/notebooks/load_note_by_title/", dict(
|
||||
notebook_id = self.notebook.object_id,
|
||||
note_title = "my title",
|
||||
), session_id = self.session_id )
|
||||
|
||||
assert result[ "note" ] == None
|
||||
|
||||
# make sure the new title is now loadable from the notebook
|
||||
result = self.http_post( "/notebooks/load_note_by_title/", dict(
|
||||
notebook_id = self.notebook.object_id,
|
||||
note_title = "new title",
|
||||
), session_id = self.session_id )
|
||||
|
||||
note = result[ "note" ]
|
||||
|
||||
assert note.object_id == self.note.object_id
|
||||
assert note.title == self.note.title
|
||||
assert note.contents == self.note.contents
|
||||
assert note.deleted_from == None
|
||||
|
||||
# make sure the old title can no longer be loaded from the trash
|
||||
result = self.http_post( "/notebooks/load_note_by_title/", dict(
|
||||
notebook_id = self.notebook.trash.object_id,
|
||||
note_title = "my title",
|
||||
), session_id = self.session_id )
|
||||
|
||||
assert result[ "note" ] == None
|
||||
|
||||
# make sure the new title is not loadable from the trash either
|
||||
result = self.http_post( "/notebooks/load_note_by_title/", dict(
|
||||
notebook_id = self.notebook.trash.object_id,
|
||||
note_title = "new title",
|
||||
), session_id = self.session_id )
|
||||
|
||||
assert result[ "note" ] == None
|
||||
|
||||
def test_save_unchanged_note( self, startup = False ):
|
||||
self.login()
|
||||
|
||||
# save over an existing note supplying new contents and a new title
|
||||
# save over an existing note, supplying new contents and a new title
|
||||
previous_revision = self.note.revision
|
||||
new_note_contents = u"<h3>new title</h3>new blah"
|
||||
self.http_post( "/notebooks/save_note/", dict(
|
||||
|
@ -401,6 +461,60 @@ class Test_notebooks( Test_controller ):
|
|||
assert note.contents == self.note.contents
|
||||
assert note.revision == previous_revision
|
||||
|
||||
def test_save_unchanged_deleted_note( self, startup = False ):
|
||||
self.login()
|
||||
|
||||
result = self.http_post( "/notebooks/delete_note/", dict(
|
||||
notebook_id = self.notebook.object_id,
|
||||
note_id = self.note.object_id,
|
||||
), session_id = self.session_id )
|
||||
|
||||
# save over an existing deleted note, supplying new contents and a new title
|
||||
previous_revision = self.note.revision
|
||||
new_note_contents = u"<h3>new title</h3>new blah"
|
||||
self.http_post( "/notebooks/save_note/", dict(
|
||||
notebook_id = self.notebook.object_id,
|
||||
note_id = self.note.object_id,
|
||||
contents = new_note_contents,
|
||||
startup = startup,
|
||||
previous_revision = previous_revision,
|
||||
), session_id = self.session_id )
|
||||
|
||||
# now attempt to save over that note again without changing the contents
|
||||
previous_revision = self.note.revision
|
||||
result = self.http_post( "/notebooks/save_note/", dict(
|
||||
notebook_id = self.notebook.object_id,
|
||||
note_id = self.note.object_id,
|
||||
contents = new_note_contents,
|
||||
startup = startup,
|
||||
previous_revision = previous_revision,
|
||||
), session_id = self.session_id )
|
||||
|
||||
# assert that the note wasn't actually updated the second time
|
||||
assert result[ "new_revision" ] == None
|
||||
assert result[ "previous_revision" ] == previous_revision
|
||||
|
||||
result = self.http_post( "/notebooks/load_note_by_title/", dict(
|
||||
notebook_id = self.notebook.object_id,
|
||||
note_title = "new title",
|
||||
), session_id = self.session_id )
|
||||
|
||||
note = result[ "note" ]
|
||||
|
||||
assert note.object_id == self.note.object_id
|
||||
assert note.title == self.note.title
|
||||
assert note.contents == self.note.contents
|
||||
assert note.revision == previous_revision
|
||||
assert note.deleted_from == None
|
||||
|
||||
# make sure the note is not loadable from the trash
|
||||
result = self.http_post( "/notebooks/load_note_by_title/", dict(
|
||||
notebook_id = self.notebook.trash.object_id,
|
||||
note_title = "new title",
|
||||
), session_id = self.session_id )
|
||||
|
||||
assert result[ "note" ] == None
|
||||
|
||||
def test_save_unchanged_note_with_startup_change( self, startup = False ):
|
||||
self.login()
|
||||
|
||||
|
|
Reference in New Issue