The username of the author of a forum post now shows up in the UI.
This commit is contained in:
parent
c636850cf0
commit
dccab45de3
|
@ -10,7 +10,8 @@ class Note( Persistent ):
|
||||||
TITLE_PATTERN = re.compile( u"<h3>(.*?)</h3>", flags = re.IGNORECASE )
|
TITLE_PATTERN = re.compile( u"<h3>(.*?)</h3>", flags = re.IGNORECASE )
|
||||||
|
|
||||||
def __init__( self, object_id, revision = None, title = None, contents = None, notebook_id = None,
|
def __init__( self, object_id, revision = None, title = None, contents = None, notebook_id = None,
|
||||||
startup = None, deleted_from_id = None, rank = None, user_id = None, creation = None, summary = None ):
|
startup = None, deleted_from_id = None, rank = None, user_id = None,
|
||||||
|
username = None, creation = None, summary = None ):
|
||||||
"""
|
"""
|
||||||
Create a new note with the given id and contents.
|
Create a new note with the given id and contents.
|
||||||
|
|
||||||
|
@ -32,6 +33,8 @@ class Note( Persistent ):
|
||||||
@param rank: indicates numeric ordering of this note in relation to other startup notes
|
@param rank: indicates numeric ordering of this note in relation to other startup notes
|
||||||
@type user_id: unicode or NoneType
|
@type user_id: unicode or NoneType
|
||||||
@param user_id: id of the user who most recently updated this note object (optional)
|
@param user_id: id of the user who most recently updated this note object (optional)
|
||||||
|
@type username: unicode or NoneType
|
||||||
|
@param username: username of the user who most recently updated this note object (optional)
|
||||||
@type creation: datetime or NoneType
|
@type creation: datetime or NoneType
|
||||||
@param creation: creation timestamp of the object (optional, defaults to None)
|
@param creation: creation timestamp of the object (optional, defaults to None)
|
||||||
@type summary: unicode or NoneType
|
@type summary: unicode or NoneType
|
||||||
|
@ -48,10 +51,12 @@ class Note( Persistent ):
|
||||||
self.__deleted_from_id = deleted_from_id
|
self.__deleted_from_id = deleted_from_id
|
||||||
self.__rank = rank
|
self.__rank = rank
|
||||||
self.__user_id = user_id
|
self.__user_id = user_id
|
||||||
|
self.__username = username
|
||||||
self.__creation = creation
|
self.__creation = creation
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def create( object_id, contents = None, notebook_id = None, startup = None, rank = None, user_id = None, creation = None, summary = None ):
|
def create( object_id, contents = None, notebook_id = None, startup = None, rank = None,
|
||||||
|
user_id = None, username = None, creation = None, summary = None ):
|
||||||
"""
|
"""
|
||||||
Convenience constructor for creating a new note.
|
Convenience constructor for creating a new note.
|
||||||
|
|
||||||
|
@ -67,6 +72,8 @@ class Note( Persistent ):
|
||||||
@param rank: indicates numeric ordering of this note in relation to other startup notes
|
@param rank: indicates numeric ordering of this note in relation to other startup notes
|
||||||
@type user_id: unicode or NoneType
|
@type user_id: unicode or NoneType
|
||||||
@param user_id: id of the user who most recently updated this note object (optional)
|
@param user_id: id of the user who most recently updated this note object (optional)
|
||||||
|
@type username: unicode or NoneType
|
||||||
|
@param username: username of the user who most recently updated this note object (optional)
|
||||||
@type creation: datetime or NoneType
|
@type creation: datetime or NoneType
|
||||||
@param creation: creation timestamp of the object (optional, defaults to None)
|
@param creation: creation timestamp of the object (optional, defaults to None)
|
||||||
@type summary: unicode or NoneType
|
@type summary: unicode or NoneType
|
||||||
|
@ -74,7 +81,11 @@ class Note( Persistent ):
|
||||||
@rtype: Note
|
@rtype: Note
|
||||||
@return: newly constructed note
|
@return: newly constructed note
|
||||||
"""
|
"""
|
||||||
note = Note( object_id, notebook_id = notebook_id, startup = startup, rank = rank, user_id = user_id, creation = creation, summary = summary )
|
note = Note(
|
||||||
|
object_id, notebook_id = notebook_id, startup = startup, rank = rank, user_id = user_id,
|
||||||
|
username = username, creation = creation, summary = summary
|
||||||
|
)
|
||||||
|
|
||||||
note.contents = contents
|
note.contents = contents
|
||||||
|
|
||||||
return note
|
return note
|
||||||
|
@ -175,6 +186,7 @@ class Note( Persistent ):
|
||||||
title = self.__title,
|
title = self.__title,
|
||||||
deleted_from_id = self.__deleted_from_id,
|
deleted_from_id = self.__deleted_from_id,
|
||||||
user_id = self.__user_id,
|
user_id = self.__user_id,
|
||||||
|
username = self.__username,
|
||||||
creation = self.__creation,
|
creation = self.__creation,
|
||||||
) )
|
) )
|
||||||
|
|
||||||
|
@ -188,4 +200,5 @@ class Note( Persistent ):
|
||||||
deleted_from_id = property( lambda self: self.__deleted_from_id, __set_deleted_from_id )
|
deleted_from_id = property( lambda self: self.__deleted_from_id, __set_deleted_from_id )
|
||||||
rank = property( lambda self: self.__rank, __set_rank )
|
rank = property( lambda self: self.__rank, __set_rank )
|
||||||
user_id = property( lambda self: self.__user_id, __set_user_id )
|
user_id = property( lambda self: self.__user_id, __set_user_id )
|
||||||
|
username = property( lambda self: self.__username )
|
||||||
creation = property( lambda self: self.__creation )
|
creation = property( lambda self: self.__creation )
|
||||||
|
|
|
@ -173,12 +173,13 @@ class Notebook( Persistent ):
|
||||||
select
|
select
|
||||||
note_current.id, note_current.revision, note_current.title, note_current.contents,
|
note_current.id, note_current.revision, note_current.title, note_current.contents,
|
||||||
note_current.notebook_id, note_current.startup, note_current.deleted_from_id,
|
note_current.notebook_id, note_current.startup, note_current.deleted_from_id,
|
||||||
note_current.rank, note_current.user_id, note_creation.revision as creation
|
note_current.rank, note_current.user_id, luminotes_user_current.username, note_creation.revision as creation
|
||||||
from
|
from
|
||||||
note_current,
|
note_current, luminotes_user_current,
|
||||||
( select id, min( revision ) as revision from note where notebook_id = %s group by id ) as note_creation
|
( select id, min( revision ) as revision from note where notebook_id = %s group by id ) as note_creation
|
||||||
where
|
where
|
||||||
notebook_id = %s and note_current.id = note_creation.id
|
notebook_id = %s and note_current.id = note_creation.id and
|
||||||
|
note_current.user_id = luminotes_user_current.id
|
||||||
order by
|
order by
|
||||||
creation %s
|
creation %s
|
||||||
limit %d offset %d;
|
limit %d offset %d;
|
||||||
|
|
|
@ -13,10 +13,11 @@ class Test_note( object ):
|
||||||
self.startup = False
|
self.startup = False
|
||||||
self.rank = 17.5
|
self.rank = 17.5
|
||||||
self.user_id = u"me"
|
self.user_id = u"me"
|
||||||
|
self.username = u"myname"
|
||||||
self.creation = datetime.now()
|
self.creation = datetime.now()
|
||||||
self.delta = timedelta( seconds = 1 )
|
self.delta = timedelta( seconds = 1 )
|
||||||
|
|
||||||
self.note = Note.create( self.object_id, self.contents, self.notebook_id, self.startup, self.rank, self.user_id, self.creation, self.summary )
|
self.note = Note.create( self.object_id, self.contents, self.notebook_id, self.startup, self.rank, self.user_id, self.username, self.creation, self.summary )
|
||||||
|
|
||||||
def test_create( self ):
|
def test_create( self ):
|
||||||
assert self.note.object_id == self.object_id
|
assert self.note.object_id == self.object_id
|
||||||
|
@ -29,6 +30,7 @@ class Test_note( object ):
|
||||||
assert self.note.deleted_from_id == None
|
assert self.note.deleted_from_id == None
|
||||||
assert self.note.rank == self.rank
|
assert self.note.rank == self.rank
|
||||||
assert self.note.user_id == self.user_id
|
assert self.note.user_id == self.user_id
|
||||||
|
assert self.note.username == self.username
|
||||||
assert self.note.creation == self.creation
|
assert self.note.creation == self.creation
|
||||||
|
|
||||||
def test_set_contents( self ):
|
def test_set_contents( self ):
|
||||||
|
@ -47,6 +49,7 @@ class Test_note( object ):
|
||||||
assert self.note.deleted_from_id == None
|
assert self.note.deleted_from_id == None
|
||||||
assert self.note.rank == self.rank
|
assert self.note.rank == self.rank
|
||||||
assert self.note.user_id == self.user_id
|
assert self.note.user_id == self.user_id
|
||||||
|
assert self.note.username == self.username
|
||||||
assert self.note.creation == self.creation
|
assert self.note.creation == self.creation
|
||||||
|
|
||||||
def test_set_contents_with_title_with_trailing_whitespace( self ):
|
def test_set_contents_with_title_with_trailing_whitespace( self ):
|
||||||
|
@ -65,6 +68,7 @@ class Test_note( object ):
|
||||||
assert self.note.deleted_from_id == None
|
assert self.note.deleted_from_id == None
|
||||||
assert self.note.rank == self.rank
|
assert self.note.rank == self.rank
|
||||||
assert self.note.user_id == self.user_id
|
assert self.note.user_id == self.user_id
|
||||||
|
assert self.note.username == self.username
|
||||||
assert self.note.creation == self.creation
|
assert self.note.creation == self.creation
|
||||||
|
|
||||||
def test_set_contents_with_title_with_trailing_nbsp( self ):
|
def test_set_contents_with_title_with_trailing_nbsp( self ):
|
||||||
|
@ -83,6 +87,7 @@ class Test_note( object ):
|
||||||
assert self.note.deleted_from_id == None
|
assert self.note.deleted_from_id == None
|
||||||
assert self.note.rank == self.rank
|
assert self.note.rank == self.rank
|
||||||
assert self.note.user_id == self.user_id
|
assert self.note.user_id == self.user_id
|
||||||
|
assert self.note.username == self.username
|
||||||
assert self.note.creation == self.creation
|
assert self.note.creation == self.creation
|
||||||
|
|
||||||
def test_set_contents_with_title_with_internal_nbsp( self ):
|
def test_set_contents_with_title_with_internal_nbsp( self ):
|
||||||
|
@ -101,6 +106,7 @@ class Test_note( object ):
|
||||||
assert self.note.deleted_from_id == None
|
assert self.note.deleted_from_id == None
|
||||||
assert self.note.rank == self.rank
|
assert self.note.rank == self.rank
|
||||||
assert self.note.user_id == self.user_id
|
assert self.note.user_id == self.user_id
|
||||||
|
assert self.note.username == self.username
|
||||||
assert self.note.creation == self.creation
|
assert self.note.creation == self.creation
|
||||||
|
|
||||||
def test_set_contents_with_html_title( self ):
|
def test_set_contents_with_html_title( self ):
|
||||||
|
@ -120,6 +126,7 @@ class Test_note( object ):
|
||||||
assert self.note.deleted_from_id == None
|
assert self.note.deleted_from_id == None
|
||||||
assert self.note.rank == self.rank
|
assert self.note.rank == self.rank
|
||||||
assert self.note.user_id == self.user_id
|
assert self.note.user_id == self.user_id
|
||||||
|
assert self.note.username == self.username
|
||||||
assert self.note.creation == self.creation
|
assert self.note.creation == self.creation
|
||||||
|
|
||||||
def test_set_contents_with_multiple_titles( self ):
|
def test_set_contents_with_multiple_titles( self ):
|
||||||
|
@ -139,6 +146,7 @@ class Test_note( object ):
|
||||||
assert self.note.deleted_from_id == None
|
assert self.note.deleted_from_id == None
|
||||||
assert self.note.rank == self.rank
|
assert self.note.rank == self.rank
|
||||||
assert self.note.user_id == self.user_id
|
assert self.note.user_id == self.user_id
|
||||||
|
assert self.note.username == self.username
|
||||||
assert self.note.creation == self.creation
|
assert self.note.creation == self.creation
|
||||||
|
|
||||||
def test_replace_contents( self ):
|
def test_replace_contents( self ):
|
||||||
|
@ -158,6 +166,7 @@ class Test_note( object ):
|
||||||
assert self.note.deleted_from_id == None
|
assert self.note.deleted_from_id == None
|
||||||
assert self.note.rank == self.rank
|
assert self.note.rank == self.rank
|
||||||
assert self.note.user_id == self.user_id
|
assert self.note.user_id == self.user_id
|
||||||
|
assert self.note.username == self.username
|
||||||
assert self.note.creation == self.creation
|
assert self.note.creation == self.creation
|
||||||
|
|
||||||
def test_set_summary( self ):
|
def test_set_summary( self ):
|
||||||
|
@ -175,6 +184,7 @@ class Test_note( object ):
|
||||||
assert self.note.deleted_from_id == None
|
assert self.note.deleted_from_id == None
|
||||||
assert self.note.rank == self.rank
|
assert self.note.rank == self.rank
|
||||||
assert self.note.user_id == self.user_id
|
assert self.note.user_id == self.user_id
|
||||||
|
assert self.note.username == self.username
|
||||||
assert self.note.creation == self.creation
|
assert self.note.creation == self.creation
|
||||||
|
|
||||||
def test_set_notebook_id( self ):
|
def test_set_notebook_id( self ):
|
||||||
|
@ -223,6 +233,7 @@ class Test_note( object ):
|
||||||
assert d.get( "title" ) == self.title
|
assert d.get( "title" ) == self.title
|
||||||
assert d.get( "deleted_from_id" ) == None
|
assert d.get( "deleted_from_id" ) == None
|
||||||
assert d.get( "user_id" ) == self.user_id
|
assert d.get( "user_id" ) == self.user_id
|
||||||
|
assert d.get( "username" ) == self.username
|
||||||
assert d.get( "creation" ) == self.note.creation
|
assert d.get( "creation" ) == self.note.creation
|
||||||
|
|
||||||
|
|
||||||
|
@ -236,6 +247,7 @@ class Test_note_blank( Test_note ):
|
||||||
self.startup = False
|
self.startup = False
|
||||||
self.rank = None
|
self.rank = None
|
||||||
self.user_id = None
|
self.user_id = None
|
||||||
|
self.username = None
|
||||||
self.creation = None
|
self.creation = None
|
||||||
self.delta = timedelta( seconds = 1 )
|
self.delta = timedelta( seconds = 1 )
|
||||||
|
|
||||||
|
@ -252,4 +264,5 @@ class Test_note_blank( Test_note ):
|
||||||
assert self.note.deleted_from_id == None
|
assert self.note.deleted_from_id == None
|
||||||
assert self.note.rank == None
|
assert self.note.rank == None
|
||||||
assert self.note.user_id == None
|
assert self.note.user_id == None
|
||||||
|
assert self.note.username == None
|
||||||
assert self.note.creation == None
|
assert self.note.creation == None
|
||||||
|
|
|
@ -286,7 +286,8 @@ Wiki.prototype.populate = function ( startup_notes, current_notes, note_read_wri
|
||||||
startup_note.revision,
|
startup_note.revision,
|
||||||
startup_note.creation,
|
startup_note.creation,
|
||||||
this.notebook.read_write, false, focus, null,
|
this.notebook.read_write, false, focus, null,
|
||||||
startup_note.user_id
|
startup_note.user_id,
|
||||||
|
startup_note.username
|
||||||
);
|
);
|
||||||
|
|
||||||
if ( startup_note.title )
|
if ( startup_note.title )
|
||||||
|
@ -312,7 +313,8 @@ Wiki.prototype.populate = function ( startup_notes, current_notes, note_read_wri
|
||||||
note.revision,
|
note.revision,
|
||||||
note.creation,
|
note.creation,
|
||||||
read_write, false, focus, null,
|
read_write, false, focus, null,
|
||||||
note.user_id
|
note.user_id,
|
||||||
|
note.username
|
||||||
);
|
);
|
||||||
focus = false;
|
focus = false;
|
||||||
}
|
}
|
||||||
|
@ -477,7 +479,7 @@ Wiki.prototype.create_blank_editor = function ( event ) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var editor = this.create_editor( undefined, undefined, undefined, undefined, undefined, this.notebook.read_write, true, true, null, this.user.object_id );
|
var editor = this.create_editor( undefined, undefined, undefined, undefined, undefined, this.notebook.read_write, true, true, null, this.user.object_id, this.user.username );
|
||||||
this.increment_total_notes_count();
|
this.increment_total_notes_count();
|
||||||
this.blank_editor_id = editor.id;
|
this.blank_editor_id = editor.id;
|
||||||
signal( this, "note_added", editor );
|
signal( this, "note_added", editor );
|
||||||
|
@ -732,6 +734,7 @@ Wiki.prototype.parse_loaded_editor = function ( result, note_title, requested_re
|
||||||
var note_text = result.note.contents;
|
var note_text = result.note.contents;
|
||||||
var deleted_from_id = result.note.deleted;
|
var deleted_from_id = result.note.deleted;
|
||||||
var user_id = result.note.user_id;
|
var user_id = result.note.user_id;
|
||||||
|
var username = result.note.username;
|
||||||
} else {
|
} else {
|
||||||
// if the title looks like a URL, then make it a link to an external site
|
// if the title looks like a URL, then make it a link to an external site
|
||||||
if ( /^\w+:\/\//.test( note_title ) ) {
|
if ( /^\w+:\/\//.test( note_title ) ) {
|
||||||
|
@ -747,6 +750,7 @@ Wiki.prototype.parse_loaded_editor = function ( result, note_title, requested_re
|
||||||
var actual_revision = null;
|
var actual_revision = null;
|
||||||
var actual_creation = null;
|
var actual_creation = null;
|
||||||
var user_id = null;
|
var user_id = null;
|
||||||
|
var username = null;
|
||||||
this.increment_total_notes_count();
|
this.increment_total_notes_count();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -756,7 +760,7 @@ Wiki.prototype.parse_loaded_editor = function ( result, note_title, requested_re
|
||||||
var read_write = this.notebook.read_write;
|
var read_write = this.notebook.read_write;
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
var editor = this.create_editor( id, note_text, deleted_from_id, actual_revision, actual_creation, read_write, true, false, position_after, user_id );
|
var editor = this.create_editor( id, note_text, deleted_from_id, actual_revision, actual_creation, read_write, true, false, position_after, user_id, username );
|
||||||
if ( !requested_revision )
|
if ( !requested_revision )
|
||||||
connect( editor, "init_complete", function () { signal( self, "note_added", editor ); } );
|
connect( editor, "init_complete", function () { signal( self, "note_added", editor ); } );
|
||||||
id = editor.id;
|
id = editor.id;
|
||||||
|
@ -766,7 +770,7 @@ Wiki.prototype.parse_loaded_editor = function ( result, note_title, requested_re
|
||||||
link.href = "/notebooks/" + this.notebook_id + "?note_id=" + id;
|
link.href = "/notebooks/" + this.notebook_id + "?note_id=" + id;
|
||||||
}
|
}
|
||||||
|
|
||||||
Wiki.prototype.create_editor = function ( id, note_text, deleted_from_id, revision, creation, read_write, highlight, focus, position_after, user_id ) {
|
Wiki.prototype.create_editor = function ( id, note_text, deleted_from_id, revision, creation, read_write, highlight, focus, position_after, user_id, username ) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var dirty = false;
|
var dirty = false;
|
||||||
var own_notes_only = false;
|
var own_notes_only = false;
|
||||||
|
@ -809,8 +813,7 @@ Wiki.prototype.create_editor = function ( id, note_text, deleted_from_id, revisi
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( creation ) {
|
if ( creation ) {
|
||||||
// FIXME: should be username, not user_id
|
note_text = this.make_byline( username, creation ) + note_text;
|
||||||
note_text = this.make_byline( user_id, creation ) + note_text;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var startup = this.startup_notes[ id ];
|
var startup = this.startup_notes[ id ];
|
||||||
|
@ -1035,6 +1038,9 @@ Wiki.prototype.editor_focused = function ( editor, synchronous ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Wiki.prototype.make_byline = function ( username, creation ) {
|
Wiki.prototype.make_byline = function ( username, creation ) {
|
||||||
|
if ( username == "anonymous" )
|
||||||
|
username = "admin";
|
||||||
|
|
||||||
if ( username )
|
if ( username )
|
||||||
var by = ' by ' + username;
|
var by = ' by ' + username;
|
||||||
else
|
else
|
||||||
|
|
|
@ -62,6 +62,7 @@ class Main_page( Page ):
|
||||||
u"revision" : startup_note.revision,
|
u"revision" : startup_note.revision,
|
||||||
u"deleted_from_id" : startup_note.deleted_from_id,
|
u"deleted_from_id" : startup_note.deleted_from_id,
|
||||||
u"user_id": startup_note.user_id,
|
u"user_id": startup_note.user_id,
|
||||||
|
u"username": startup_note.username,
|
||||||
} for startup_note in startup_notes ]
|
} for startup_note in startup_notes ]
|
||||||
|
|
||||||
note_dicts = [ {
|
note_dicts = [ {
|
||||||
|
@ -69,6 +70,7 @@ class Main_page( Page ):
|
||||||
u"revision" : note.revision,
|
u"revision" : note.revision,
|
||||||
u"deleted_from_id" : note.deleted_from_id,
|
u"deleted_from_id" : note.deleted_from_id,
|
||||||
u"user_id": note.user_id,
|
u"user_id": note.user_id,
|
||||||
|
u"username": note.username,
|
||||||
u"creation" : note.creation,
|
u"creation" : note.creation,
|
||||||
} for note in notes ]
|
} for note in notes ]
|
||||||
|
|
||||||
|
|
Reference in New Issue