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/controller/test/Stub_database.py
Dan Helfman 613ee8a217 Completely revamped the way the main page and the notes on it are loaded by
the client. Previously, the main page would load as mostly blank, then the
client would immediately issue two async json calls to load the user and
notebook data, including startup notes. Now, the main page loads with the note
data actually as part of the page. If JavaScript is off, then you see all the
notes displayed, including startup notes and any designated note. If
JavaScript is on, then those "static" notes are instantly hidden and their
contents are loaded into iframes for editing/display.

The real upshot is that Luminotes in read-only mode is now more useful when
JavaScript is off, and actually displays notes and their contents. This is
very useful for search engine indexing.

Updated all Python unit tests. Still have to get to JavaScript unit tests,
what few their are.
2007-10-16 21:37:12 +00:00

75 lines
2.2 KiB
Python

from copy import copy
class Stub_database( object ):
def __init__( self, connection = None ):
# map of object id to list of saved objects (presumably in increasing order of revisions)
self.objects = {}
self.user_notebook = {} # map of user_id to ( notebook_id, read_write )
self.last_saved_obj = None
self.__next_id = 0
def save( self, obj, commit = False ):
self.last_saved_obj = obj
if obj.object_id in self.objects:
self.objects[ obj.object_id ].append( copy( obj ) )
else:
self.objects[ obj.object_id ] = [ copy( obj ) ]
def load( self, Object_type, object_id, revision = None ):
obj_list = self.objects.get( object_id )
if not obj_list:
return None
# if a particular revision wasn't requested, just return the most recently saved object
# matching the given object_id
if revision is None:
if not isinstance( obj_list[ -1 ], Object_type ):
return None
return copy( obj_list[ -1 ] )
# a particular revision was requested, so pick it out of the objects matching the given id
matching_objs = [ obj for obj in obj_list if str( obj.revision ) == str( revision ) ]
if len( matching_objs ) > 0:
if not isinstance( matching_objs[ -1 ], Object_type ):
return None
return copy( matching_objs[ -1 ] )
return None
def select_one( self, Object_type, sql_command ):
if callable( sql_command ):
result = sql_command( self )
if isinstance( result, list ):
if len( result ) == 0: return None
return result[ 0 ]
return result
raise NotImplementedError( sql_command )
def select_many( self, Object_type, sql_command ):
if callable( sql_command ):
result = sql_command( self )
if isinstance( result, list ):
return result
return [ result ]
raise NotImplementedError( sql_command )
def execute( self, sql_command, commit = False ):
if callable( sql_command ):
return sql_command( self )
raise NotImplementedError( sql_command )
def next_id( self, Object_type, commit = True ):
self.__next_id += 1
return unicode( self.__next_id )
def commit( self ):
pass
def close( self ):
pass