Archived
1
0
This repository has been archived on 2023-12-16. You can view files and clone it, but cannot push or open issues or pull requests.
luminotes/model/Note.py
Dan Helfman f2eac9cb1f Implemented a basic trash, including undo upon note deletion and undeletion from the trash:
* model.Note has a deleted_from member to indicate the notebook id it was deleted from (if any)
 * controller.Notebooks sets the deleted_from member and makes all deleted notes startup notes in the trash
 * new controller.Notebooks.undelete_note() method
 * split up the idea of UI messages into errors and informational messages, with separate CSS
 * updated Editor and Wiki UI code to deal with new deleted_from variable
 * added "undelete" button when viewing a deleted note, and "delete" changes to "delete forever"
 * added a "trash" link to the notebook links
 * reorganized responsibilities for displaying notebook/user links among Wiki.populate() and Wiki.display_user()
 * when deleting messages in a notebook with a trash, displaying "The note has been moved to the trash"...
   with a working undo button!
 * tweaked focusing logic in display_search_results(), which has been renamed to display_loaded_notes()
2007-08-07 01:48:43 +00:00

67 lines
1.8 KiB
Python

import re
from Persistent import Persistent
from controller.Html_nuker import Html_nuker
class Note( Persistent ):
"""
An single textual wiki note.
"""
TITLE_PATTERN = re.compile( u"<h3>(.*)</h3>", flags = re.IGNORECASE )
def __setstate__( self, state ):
if "_Note__deleted_from" not in state:
state[ "_Note__deleted_from" ] = False
self.__dict__.update( state )
def __init__( self, id, contents = None ):
"""
Create a new note with the given id and contents.
@type id: unicode
@param id: id of the note
@type contents: unicode or NoneType
@param contents: initial contents of the note (optional)
@rtype: Note
@return: newly constructed note
"""
Persistent.__init__( self, id )
self.__title = None
self.__contents = None or ""
self.__deleted_from = None
self.__set_contents( contents, new_revision = False )
def __set_contents( self, contents, new_revision = True ):
if new_revision:
self.update_revision()
self.__contents = contents
# parse title out of the beginning of the contents
result = Note.TITLE_PATTERN.search( contents )
if result:
self.__title = result.groups()[ 0 ]
self.__title = Html_nuker( allow_refs = True ).nuke( self.__title )
else:
self.__title = None
def __set_deleted_from( self, deleted_from ):
self.__deleted_from = deleted_from
self.update_revision()
def to_dict( self ):
d = Persistent.to_dict( self )
d.update( dict(
contents = self.__contents,
title = self.__title,
deleted_from = self.__deleted_from,
) )
return d
contents = property( lambda self: self.__contents, __set_contents )
title = property( lambda self: self.__title )
deleted_from = property( lambda self: self.__deleted_from, __set_deleted_from )