diff --git a/controller/Notebooks.py b/controller/Notebooks.py index 44493c3..9f86db8 100644 --- a/controller/Notebooks.py +++ b/controller/Notebooks.py @@ -723,6 +723,8 @@ class Notebooks( object ): result = self.__users.current( user_id ) result.update( self.contents( notebook_id, user_id = user_id ) ) - result[ u"notes" ] = recent_notes + result[ "notes" ] = recent_notes + result[ "start" ] = start + result[ "count" ] = count return result diff --git a/controller/Root.py b/controller/Root.py index ccbec21..49980f1 100644 --- a/controller/Root.py +++ b/controller/Root.py @@ -118,7 +118,7 @@ class Root( object ): count = Valid_int( min = 1, max = 50 ), user_id = Valid_id( none_okay = True ), ) - def blog( self, start = 0, count = 10, user_id = None ): + def blog( self, start = 0, count = 3, user_id = None ): """ Provide the information necessary to display the blog notebook with notes in reverse chronological order. diff --git a/controller/test/Test_notebooks.py b/controller/test/Test_notebooks.py index e5993bb..d555986 100644 --- a/controller/test/Test_notebooks.py +++ b/controller/test/Test_notebooks.py @@ -1673,6 +1673,8 @@ class Test_notebooks( Test_controller ): assert result.get( u"parent_id" ) == None assert result.get( u"note_read_write" ) in ( None, True ) + assert result.get( u"start" ) == 0 + assert result.get( u"count" ) == 10 user = self.database.load( User, self.user.object_id ) assert user.storage_bytes == 0 @@ -1700,6 +1702,8 @@ class Test_notebooks( Test_controller ): assert result.get( u"parent_id" ) == None assert result.get( u"note_read_write" ) in ( None, True ) + assert result.get( u"start" ) == 1 + assert result.get( u"count" ) == 10 user = self.database.load( User, self.user.object_id ) assert user.storage_bytes == 0 @@ -1727,6 +1731,8 @@ class Test_notebooks( Test_controller ): assert result.get( u"parent_id" ) == None assert result.get( u"note_read_write" ) in ( None, True ) + assert result.get( u"start" ) == 0 + assert result.get( u"count" ) == 1 user = self.database.load( User, self.user.object_id ) assert user.storage_bytes == 0 diff --git a/model/Notebook.py b/model/Notebook.py index 9b6b2b4..3f3d29d 100644 --- a/model/Notebook.py +++ b/model/Notebook.py @@ -117,6 +117,8 @@ class Notebook( Persistent ): ( select id, min( revision ) as revision from note where notebook_id = %s group by id ) as note_creation where notebook_id = %s and note_current.id = note_creation.id + order by + creation desc offset %d limit %d; """ % ( quote( self.object_id ), quote( self.object_id ), start, count ) diff --git a/view/Main_page.py b/view/Main_page.py index b31d93e..14a72b7 100644 --- a/view/Main_page.py +++ b/view/Main_page.py @@ -23,6 +23,8 @@ class Main_page( Page ): total_notes_count = None, notes = None, note_read_write = True, + start = None, + count = None, ): startup_note_ids = [ startup_note.object_id for startup_note in startup_notes ] @@ -62,6 +64,15 @@ class Main_page( Page ): else: title = None + if notebook.name == u"Luminotes": + notebook_path = u"/" + elif notebook.name == u"Luminotes user guide": + notebook_path = u"/guide" + elif notebook.name == u"Luminotes blog": + notebook_path = u"/blog" + else: + notebook_path = u"/notebooks/%s" % notebook.object_id + Page.__init__( self, title, @@ -102,8 +113,8 @@ class Main_page( Page ): ), Rounded_div( ( notebook.name == u"trash" ) and u"trash_notebook" or u"current_notebook", - ( len( notes ) > 0 and notebook.name != u"Luminotes" ) and \ - A( Strong( notebook.name ), href = u"/notebooks/%s" % notebook.object_id ) \ + ( len( notes ) > 0 ) and \ + A( Strong( notebook.name ), href = notebook_path ) \ or Strong( notebook.name ), parent_id and Span( u" | ", @@ -134,6 +145,17 @@ class Main_page( Page ): u"document.getElementById( 'static_notes' ).style.display = 'none';", type = u"text/javascript", ), + # make page navigation for those notebooks that require it (such as the blog) + ( start is not None and count is not None ) and Div( + ( start > 0 ) and Div( A( + u"previous page", + href = "%s?start=%d&count=%d" % ( notebook_path, max( start - count, 0 ), count ), + ) ) or None, + ( start + count < total_notes_count ) and Div( A( + u"next_page", + href = "%s?start=%d&count=%d" % ( notebook_path, min( start + count, total_notes_count - 1 ), count ), + ) ) or None, + ) or None, id = u"notebook_background", corners = ( u"tl", ), ),