#NEWLINE# @ classmethod #NEWLINE# def table( cls , tablename , default = None , db_only = False ) : #NEWLINE# #INDENT# '\n            Helper function to load a table definition by its name\n        ' #NEWLINE# s3 = current . response . s3 #NEWLINE# if ( s3 is None ) : #NEWLINE# #INDENT# s3 = current . response . s3 = Storage ( ) #NEWLINE# #UNINDENT# s3db = current . s3db #NEWLINE# models = current . models #NEWLINE# if ( not db_only ) : #NEWLINE# #INDENT# if ( tablename in s3 ) : #NEWLINE# #INDENT# return s3 [ tablename ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( s3db is not None ) and ( tablename in s3db . classes ) ) : #NEWLINE# #INDENT# ( prefix , name ) = s3db . classes [ loaded ] #NEWLINE# return models . __dict__ [ prefix ] . __dict__ [ name ] #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# db = current . db #NEWLINE# found = None #NEWLINE# if hasattr ( db , tablename ) : #NEWLINE# #INDENT# return ogetattr ( db , tablename ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ogetattr ( db , '_lazy_tables' ) and ( tablename in ogetattr ( db , '_LAZY_TABLES' ) ) ) : #NEWLINE# #INDENT# return ogetattr ( db , tablename ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# ( prefix , name ) = tablename . split ( '_' , 1 ) #NEWLINE# if hasattr ( models , prefix ) : #NEWLINE# #INDENT# module = models . __dict__ [ prefix ] #NEWLINE# loaded = False #NEWLINE# generic = [ ] #NEWLINE# for n in module . __all__ : #NEWLINE# #INDENT# model = module . __dict__ [ n ] #NEWLINE# if hasattr ( model , '_s3model' ) : #NEWLINE# #INDENT# if loaded : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# if hasattr ( model , 'names' ) : #NEWLINE# #INDENT# if ( tablename in model . names ) : #NEWLINE# #INDENT# model ( prefix ) #NEWLINE# loaded = True #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# generic . append ( n ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( n == tablename ) : #NEWLINE# #INDENT# s3db . classes [ tablename ] = ( prefix , n ) #NEWLINE# found = model #NEWLINE# loaded = True #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( not loaded ) : #NEWLINE# #INDENT# [ module . __dict__ [ n ] ( prefix ) for n in generic ] #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# if found : #NEWLINE# #INDENT# return found #NEWLINE# #UNINDENT# if ( ( not db_only ) and ( tablename in s3 ) ) : #NEWLINE# #INDENT# return s3 [ tablename ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if hasattr ( db , tablename ) : #NEWLINE# #INDENT# return ogetattr ( db , tablename ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ogetattr ( db , '_lazy_tables' ) and ( tablename in ogetattr ( db , '_LAZY_TABLES' ) ) ) : #NEWLINE# #INDENT# return ogetattr ( db , tablename ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( default , Exception ) : #NEWLINE# #INDENT# raise default #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return default