witten
/
luminotes
Archived
1
0
Fork 0

When linking to a note by title, the note resolution is now

case-insensitive instead of case-sensitive.
This commit is contained in:
Dan Helfman 2008-06-25 20:04:06 -07:00
parent 708de3b7e7
commit 599971ba01
6 changed files with 57 additions and 17 deletions

4
NEWS
View File

@ -1,3 +1,7 @@
1.4.9: June 25, 2008:
* When linking to a note by title, the note resolution is now
case-insensitive instead of case-sensitive.
1.4.8: June 23, 2008:
* Replaced "add new notebook" link with new notebook button next to
"notebooks" heading.

View File

@ -378,7 +378,8 @@ class Notebooks( object ):
)
def load_note_by_title( self, notebook_id, note_title, summarize = False, user_id = None ):
"""
Return the information on a particular note by its title.
Return the information on a particular note by its title. The lookup by title is performed
case-insensitively.
@type notebook_id: unicode
@param notebook_id: id of notebook the note is in
@ -469,7 +470,8 @@ class Notebooks( object ):
)
def lookup_note_id( self, notebook_id, note_title, user_id ):
"""
Return a note's id by looking up its title.
Return a note's id by looking up its title. The lookup by title is performed
case-insensitively.
@type notebook_id: unicode
@param notebook_id: id of notebook the note is in

View File

@ -365,7 +365,7 @@ class Test_controller( object ):
for ( object_id, obj_list ) in database.objects.items():
obj = obj_list[ -1 ]
if isinstance( obj, Note ) and obj.notebook_id == self.object_id and obj.title == title:
if isinstance( obj, Note ) and obj.notebook_id == self.object_id and obj.title.lower() == title.lower():
notes.append( obj )
return notes

View File

@ -1152,6 +1152,22 @@ class Test_notebooks( Test_controller ):
user = self.database.load( User, self.user.object_id )
assert user.storage_bytes == 0
def test_load_note_by_title_case_insensitive( self ):
self.login()
result = self.http_post( "/notebooks/load_note_by_title/", dict(
notebook_id = self.notebook.object_id,
note_title = self.note.title.upper(),
), 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
user = self.database.load( User, self.user.object_id )
assert user.storage_bytes == 0
def test_load_note_by_title_without_login( self ):
result = self.http_post( "/notebooks/load_note_by_title/", dict(
notebook_id = self.notebook.object_id,
@ -1257,6 +1273,18 @@ class Test_notebooks( Test_controller ):
user = self.database.load( User, self.user.object_id )
assert user.storage_bytes == 0
def test_lookup_note_id_case_insensitive( self ):
self.login()
result = self.http_post( "/notebooks/lookup_note_id/", dict(
notebook_id = self.notebook.object_id,
note_title = self.note.title.upper(),
), session_id = self.session_id )
assert result.get( "note_id" ) == self.note.object_id
user = self.database.load( User, self.user.object_id )
assert user.storage_bytes == 0
def test_lookup_note_id_without_login( self ):
result = self.http_post( "/notebooks/lookup_note_id/", dict(
notebook_id = self.notebook.object_id,

View File

@ -159,12 +159,13 @@ class Notebook( Persistent ):
def sql_load_note_by_title( self, title ):
"""
Return a SQL string to load a particular note within this notebook by the note's title.
Return a SQL string to load a particular note within this notebook by the note's title. The
title lookup is performed case-insensitively.
@type note_id: unicode
@param note_id: title of note to load
"""
return "select id, revision, title, contents, notebook_id, startup, deleted_from_id, rank, user_id from note_current where notebook_id = %s and title = %s;" % ( quote( self.object_id ), quote( title ) )
return "select id, revision, title, contents, notebook_id, startup, deleted_from_id, rank, user_id from note_current where notebook_id = %s and lower( title ) = lower( %s );" % ( quote( self.object_id ), quote( title ) )
@staticmethod
def sql_search_notes( user_id, first_notebook_id, search_text ):

View File

@ -8,7 +8,7 @@ function Wiki( invoker ) {
this.notebook_id = getElement( "notebook_id" ).value;
this.parent_id = getElement( "parent_id" ).value; // id of the notebook containing this one
this.startup_notes = new Array(); // map of startup notes: note id to bool
this.open_editors = new Array(); // map of open notes: note title to editor
this.open_editors = new Array(); // map of open notes: lowercase note title to editor
this.search_results_editor = null; // editor for display of search results
this.invoker = invoker;
this.rate_plan = evalJSON( getElement( "rate_plan" ).value );
@ -272,7 +272,8 @@ Wiki.prototype.populate = function ( startup_notes, current_notes, note_read_wri
this.notebook.read_write, false, focus
);
this.open_editors[ startup_note.title ] = editor;
if ( startup_note.title )
this.open_editors[ startup_note.title.toLowerCase() ] = editor;
focus = false;
}
}
@ -477,9 +478,11 @@ Wiki.prototype.load_editor = function ( note_title, note_id, revision, previous_
// if there's not a valid destination note id, then load by title instead of by id
var self = this;
if ( pulldown_title || note_id == undefined || note_id == "new" || note_id == "null" ) {
var lower_note_title = note_title.toLowerCase();
// if the note_title corresponds to a "magic" note's title, then dynamically highlight or create the note
if ( note_title == "search results" ) {
var editor = this.open_editors[ note_title ];
if ( lower_note_title == "search results" ) {
var editor = this.open_editors[ lower_note_title ];
if ( editor ) {
editor.highlight();
return;
@ -488,8 +491,8 @@ Wiki.prototype.load_editor = function ( note_title, note_id, revision, previous_
this.display_search_results();
return;
}
if ( note_title == "share this notebook" ) {
var editor = this.open_editors[ note_title ];
if ( lower_note_title == "share this notebook" ) {
var editor = this.open_editors[ lower_note_title ];
if ( editor ) {
editor.highlight();
return;
@ -498,8 +501,8 @@ Wiki.prototype.load_editor = function ( note_title, note_id, revision, previous_
this.share_notebook();
return;
}
if ( note_title == "account settings" ) {
var editor = this.open_editors[ note_title ];
if ( lower_note_title == "account settings" ) {
var editor = this.open_editors[ lower_note_title ];
if ( editor ) {
editor.highlight();
return;
@ -511,7 +514,7 @@ Wiki.prototype.load_editor = function ( note_title, note_id, revision, previous_
// but if the note corresponding to the link's title is already open, highlight it and bail
if ( !revision ) {
var editor = this.open_editors[ note_title ];
var editor = this.open_editors[ lower_note_title ];
if ( editor ) {
editor.highlight();
if ( link )
@ -578,7 +581,7 @@ Wiki.prototype.resolve_link = function ( note_title, link, callback ) {
return;
// if the note corresponding to the link's title is already open, resolve the link and bail
var editor = this.open_editors[ note_title ];
var editor = this.open_editors[ note_title.toLowerCase() ];
if ( editor ) {
if ( link )
link.href = "/notebooks/" + this.notebook_id + "?note_id=" + editor.id;
@ -799,10 +802,12 @@ Wiki.prototype.editor_state_changed = function ( editor, link_clicked ) {
}
Wiki.prototype.editor_title_changed = function ( editor, old_title, new_title ) {
delete this.open_editors[ old_title ];
if ( old_title )
delete this.open_editors[ old_title.toLowerCase() ];
if ( new_title != null && !editor.empty() ) {
this.open_editors[ new_title ] = editor;
if ( new_title )
this.open_editors[ new_title.toLowerCase() ] = editor;
signal( this, "note_renamed", editor, new_title );
}
}