#NEWLINE# @ classmethod #NEWLINE# def create_new_entity( cls , **kwargs ) : #NEWLINE# #INDENT# def txn( key_name ) : #NEWLINE# #INDENT# if kwargs . has_key ( 'parent' ) : #NEWLINE# #INDENT# entity = cls . get_by_key_name ( key_name , parent = kwargs [ 'parent' ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# entity = cls . get_by_key_name ( key_name ) #NEWLINE# #UNINDENT# if ( entity is None ) : #NEWLINE# #INDENT# entity = cls ( key_name = key_name , ** kwargs ) #NEWLINE# entity . put ( ) #NEWLINE# return entity #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return None #NEWLINE# #UNINDENT# #UNINDENT# key_generator = cls . get_key_generator ( ** kwargs ) #NEWLINE# first_key_name = key_generator . next ( ) #NEWLINE# entity = db . run_in_transaction ( txn , first_key_name ) #NEWLINE# while ( entity is None ) : #NEWLINE# #INDENT# key_name = key_negerator . next ( ) #NEWLINE# entity = db . run_in_transaction ( txn , key_name ) #NEWLINE# #UNINDENT# return entity