From fc502c6c827606f4f618a69d8a05e7cc1c72a5b2 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Mon, 2 Feb 2009 13:41:09 -0800 Subject: [PATCH] Clarified the names of some of the notebook note-loading methods so that they are less confusing. --- controller/Notebooks.py | 44 +++++-------------------------- controller/test/Test_forums.py | 4 +-- controller/test/Test_notebooks.py | 22 ---------------- model/Notebook.py | 22 ++++++++++++++-- 4 files changed, 28 insertions(+), 64 deletions(-) diff --git a/controller/Notebooks.py b/controller/Notebooks.py index 949a9f9..1cd7a09 100644 --- a/controller/Notebooks.py +++ b/controller/Notebooks.py @@ -165,7 +165,7 @@ class Notebooks( object ): ) if notebook.name != u"Luminotes": - result[ "recent_notes" ] = self.__database.select_many( Note, notebook.sql_load_notes( start = 0, count = 10 ) ) + result[ "recent_notes" ] = self.__database.select_many( Note, notebook.sql_load_notes_in_update_order( start = 0, count = 10 ) ) # if the user doesn't have any storage bytes yet, they're a new user, so see what type of # conversion this is (demo or signup) @@ -288,7 +288,7 @@ class Notebooks( object ): https_url = self.__https_url, ) - recent_notes = self.__database.select_many( Note, notebook.sql_load_notes( start = 0, count = 10 ) ) + recent_notes = self.__database.select_many( Note, notebook.sql_load_notes_in_update_order( start = 0, count = 10 ) ) return dict( recent_notes = [ ( note.object_id, note.revision ) for note in recent_notes ], @@ -1020,7 +1020,7 @@ class Notebooks( object ): if not notebook or notebook.read_write == Notebook.READ_WRITE_FOR_OWN_NOTES: raise Access_error() - notes = self.__database.select_many( Note, notebook.sql_load_notes() ) + notes = self.__database.select_many( Note, notebook.sql_load_notes_in_update_order() ) for note in notes: if notebook.trash_id: @@ -1155,38 +1155,6 @@ class Notebooks( object ): notes = notes, ) - @expose( view = Json ) - @strongly_expire - @end_transaction - @grab_user_id - @validate( - notebook_id = Valid_id(), - user_id = Valid_id( none_okay = True ), - ) - def all_notes( self, notebook_id, user_id ): - """ - Return ids and titles of all notes in this notebook, sorted by reverse chronological order. - - @type notebook_id: unicode - @param notebook_id: id of notebook to pull notes from - @type user_id: unicode - @param user_id: id of current logged-in user (if any), determined by @grab_user_id - @rtype: json dict - @return: { 'notes': [ ( noteid, notetitle ) ] } - @raise Access_error: the current user doesn't have access to the given notebook - @raise Validation_error: one of the arguments is invalid - """ - notebook = self.__users.load_notebook( user_id, notebook_id ) - - if not notebook: - raise Access_error() - - notes = self.__database.select_many( Note, notebook.sql_load_notes() ) - - return dict( - notes = [ ( note.object_id, note.title ) for note in notes ] - ) - @expose( view = Html_file ) @weakly_expire @end_transaction @@ -1690,7 +1658,7 @@ class Notebooks( object ): if notebook is None: raise Access_error() - recent_notes = self.__database.select_many( Note, notebook.sql_load_notes( start = start, count = count ) ) + recent_notes = self.__database.select_many( Note, notebook.sql_load_notes_in_update_order( start = start, count = count ) ) return dict( notes = recent_notes, @@ -1718,7 +1686,7 @@ class Notebooks( object ): if notebook is None: raise Access_error() - notes = self.__database.select_many( Note, notebook.sql_load_recent_notes( start, count ) ) + notes = self.__database.select_many( Note, notebook.sql_load_notes_in_creation_order( start, count ) ) result = self.__users.current( user_id ) result.update( self.contents( notebook_id, user_id = user_id ) ) @@ -1749,7 +1717,7 @@ class Notebooks( object ): if notebook is None: raise Access_error() - notes = self.__database.select_many( Note, notebook.sql_load_recent_notes( start, count, reverse = True ) ) + notes = self.__database.select_many( Note, notebook.sql_load_notes_in_creation_order( start, count, reverse = True ) ) result = self.__users.current( user_id ) result.update( self.contents( notebook_id, user_id = user_id ) ) diff --git a/controller/test/Test_forums.py b/controller/test/Test_forums.py index 8c54b07..098d473 100644 --- a/controller/test/Test_forums.py +++ b/controller/test/Test_forums.py @@ -572,7 +572,7 @@ class Test_forums( Test_controller ): assert tags[ 0 ].name == u"forum" assert tags[ 0 ].value == u"general" - notes = self.database.select_many( Note, thread.sql_load_notes() ) + notes = self.database.select_many( Note, thread.sql_load_notes_in_update_order() ) assert notes assert len( notes ) == 1 assert notes[ 0 ].title == None @@ -618,7 +618,7 @@ class Test_forums( Test_controller ): assert tags[ 0 ].name == u"forum" assert tags[ 0 ].value == u"blog" - notes = self.database.select_many( Note, thread.sql_load_notes() ) + notes = self.database.select_many( Note, thread.sql_load_notes_in_update_order() ) assert notes assert len( notes ) == 1 assert notes[ 0 ].title == None diff --git a/controller/test/Test_notebooks.py b/controller/test/Test_notebooks.py index b4d074a..0e1dfd6 100644 --- a/controller/test/Test_notebooks.py +++ b/controller/test/Test_notebooks.py @@ -3803,28 +3803,6 @@ class Test_notebooks( Test_controller ): assert len( notes ) == 1 assert notes[ 0 ].object_id == note3.object_id - def test_all_notes( self ): - self.login() - - result = self.http_post( "/notebooks/all_notes/", dict( - notebook_id = self.notebook.object_id, - ), session_id = self.session_id ) - - notes = result.get( "notes" ) - - assert len( notes ) == 2 - assert notes[ 0 ][ 0 ] == self.note2.object_id - assert notes[ 0 ][ 1 ] == self.note2.title - assert notes[ 1 ][ 0 ] == self.note.object_id - assert notes[ 1 ][ 1 ] == self.note.title - - def test_all_notes_without_login( self ): - result = self.http_post( "/notebooks/all_notes/", dict( - notebook_id = self.notebook.object_id, - ), session_id = self.session_id ) - - assert result.get( "error" ) - def test_export_html( self ): self.login() diff --git a/model/Notebook.py b/model/Notebook.py index 5b3839b..e38b393 100644 --- a/model/Notebook.py +++ b/model/Notebook.py @@ -130,7 +130,25 @@ class Notebook( Persistent ): def sql_load_by_friendly_id( friendly_id ): return "select * from notebook_current where friendly_id( name ) = %s;" % quote( friendly_id ) - def sql_load_notes( self, start = 0, count = None ): + def sql_load_notes_in_rank_order( self, start = 0, count = None ): + """ + Return a SQL string to load a list of all the notes within this notebook. + Note: If the database backend is SQLite, a start parameter cannot be given without also + providing a count parameter. + """ + if count is not None: + limit_clause = " limit %s" % count + else: + limit_clause = "" + + if start: + offset_clause = " offset %s" % start + else: + offset_clause = "" + + return "select id, revision, title, contents, notebook_id, startup, deleted_from_id, rank, user_id from note_current where notebook_id = %s order by rank%s%s;" % ( quote( self.object_id ), limit_clause, offset_clause ) + + def sql_load_notes_in_update_order( self, start = 0, count = None ): """ Return a SQL string to load a list of all the notes within this notebook. Note: If the database backend is SQLite, a start parameter cannot be given without also @@ -160,7 +178,7 @@ class Notebook( Persistent ): """ return "select id, revision, title, contents, notebook_id, startup, deleted_from_id, rank, user_id from note_current where notebook_id = %s and startup = 't' order by rank;" % quote( self.object_id ) - def sql_load_recent_notes( self, start = 0, count = 10, reverse = False ): + def sql_load_notes_in_creation_order( self, start = 0, count = 10, reverse = False ): """ Return a SQL string to load a list of the most recently created notes within this notebook.