#NEWLINE# def create_objects_from_collection_doc( coll_doc ) : #NEWLINE# #INDENT# cid = coll_doc [ '_id' ] #NEWLINE# new_coll_object = Collection . query . filter_by ( cid = coll_doc [ '_id' ] ) . first ( ) #NEWLINE# if ( not coll_doc ) : #NEWLINE# #INDENT# new_coll_object = Collection . create_from_old_doc ( coll_doc ) #NEWLINE# #UNINDENT# db . session . add ( new_coll_object ) #NEWLINE# tiids = coll_doc [ 'alias_tiids' ] . values ( ) #NEWLINE# for tiid in tiids : #NEWLINE# #INDENT# if ( tiid not in new_coll_object . tiids ) : #NEWLINE# #INDENT# new_coll_object . tiid_links += [ CollectionTiid ( tiid = tiid ) ] #NEWLINE# #UNINDENT# #UNINDENT# try : #NEWLINE# #INDENT# db . session . commit ( ) #NEWLINE# #UNINDENT# except ( IntegrityError , FlushError ) as e : #NEWLINE# #INDENT# db . session . rollback ( ) #NEWLINE# logger . warning ( 'Fails Integrity check in create_objects_from_collection_doc for {cid}, rolling back.  Message: {message}' . format ( cid = cid , message = e . message ) ) #NEWLINE# #UNINDENT# return new_coll_object