witten
/
luminotes
Archived
1
0
Fork 0

Notebooks.summarize_note() can now optionally highlight some particular text.

This commit is contained in:
Dan Helfman 2008-08-26 19:35:50 -07:00
parent 8cad14ca34
commit f07cd2dc41
2 changed files with 16 additions and 2 deletions

View File

@ -426,7 +426,7 @@ class Notebooks( object ):
note = summarize and self.summarize_note( note ) or note,
)
def summarize_note( self, note, max_summary_length = None, word_count = None ):
def summarize_note( self, note, max_summary_length = None, word_count = None, highlight_text = None ):
"""
Create a truncated, HTML-free note summary for the given note, and then return the note with
its summary set.
@ -439,6 +439,8 @@ class Notebooks( object ):
@type word_count: int or NoneType
@param word_count: the number of words to which the summary is truncated (optional, defaults
to a reasonable number of words)
@type highlight_text: unicode or NoneType
@param highlight_text: text to emphasize within the summary (optional, defaults to no emphasis)
@rtype: model.Note or NoneType
@return: note with its summary member set, or None if no note was provided
"""
@ -485,6 +487,9 @@ class Notebooks( object ):
if truncated or word_count < len( words ):
summary += " ..."
if highlight_text:
summary = summary.replace( highlight_text, "<b>%s</b>" % highlight_text )
note.summary = summary
return note
@ -1124,7 +1129,11 @@ class Notebooks( object ):
notes = self.__database.select_many( Note, Notebook.sql_search_notes( user_id, notebook_id, search_text, self.__database.backend ) )
# make a summary for each note that doesn't have one
notes = [ note.summary and note or self.summarize_note( note, max_summary_length = 80, word_count = 30 ) for note in notes ]
notes = [
note.summary and note or
self.summarize_note( note, max_summary_length = 80, word_count = 30, highlight_text = search_text )
for note in notes
]
return dict(
notes = notes,

View File

@ -1308,6 +1308,11 @@ class Test_notebooks( Test_controller ):
assert note == None
def test_summarize_note_with_highligh_text( self ):
note = cherrypy.root.notebooks.summarize_note( self.note, highlight_text = "la" )
assert note.summary == u"b<b>la</b>h"
def test_lookup_note_id( self ):
self.login()