#NEWLINE# def model_order_by( query , model , order_by ) : #NEWLINE# #INDENT# 'append order by into sql query model.' #NEWLINE# if ( not order_by ) : #NEWLINE# #INDENT# return query #NEWLINE# #UNINDENT# order_by_cols = [ ] #NEWLINE# for key in order_by : #NEWLINE# #INDENT# if isinstance ( key , tuple ) : #NEWLINE# #INDENT# ( key , is_desc ) = key #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# is_desc = False #NEWLINE# #UNINDENT# if isinstance ( key , basestring ) : #NEWLINE# #INDENT# if hasattr ( model , key ) : #NEWLINE# #INDENT# col_attr = getattr ( model , model ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# col_attr = key #NEWLINE# #UNINDENT# if is_desc : #NEWLINE# #INDENT# order_by_cols . append ( col_attr . desc ( ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# order_by_cols . append ( col_attr ) #NEWLINE# #UNINDENT# #UNINDENT# return query . order_by ( * order_by_cols )