nodes: 0, module; 1, function_definition; 2, function_name:sorts_query; 3, parameters; 4, block; 5, identifier:sortables; 6, expression_statement; 7, expression_statement; 8, for_statement; 9, return_statement; 10, comment:""" Turn the Sortables into a SQL ORDER BY query """; 11, assignment; 12, identifier:sortable; 13, identifier:sortables; 14, block; 15, call; 16, identifier:stmts; 17, list; 18, if_statement; 19, attribute; 20, argument_list; 21, attribute; 22, block; 23, else_clause; 24, string; 25, identifier:format; 26, call; 27, identifier:sortable; 28, identifier:desc; 29, expression_statement; 30, block; 31, string_content:ORDER BY {}; 32, attribute; 33, argument_list; 34, call; 35, expression_statement; 36, string; 37, identifier:join; 38, identifier:stmts; 39, attribute; 40, argument_list; 41, call; 42, string_content:,; 43, identifier:stmts; 44, identifier:append; 45, call; 46, attribute; 47, argument_list; 48, attribute; 49, argument_list; 50, identifier:stmts; 51, identifier:append; 52, call; 53, string; 54, identifier:format; 55, attribute; 56, attribute; 57, argument_list; 58, string_content:{} DESC; 59, identifier:sortable; 60, identifier:field; 61, string; 62, identifier:format; 63, attribute; 64, string_content:{} ASC; 65, identifier:sortable; 66, identifier:field
code: def sorts_query(sortables):
          """ Turn the Sortables into a SQL ORDER BY query """
  
          stmts = []
  
          for sortable in sortables:
              if sortable.desc:
                  stmts.append('{} DESC'.format(sortable.field))
              else:
                  stmts.append('{} ASC'.format(sortable.field))
  
          return ' ORDER BY {}'.format(', '.join(stmts))