nodes: 0, module; 1, function_definition; 2, function_name:resolve_sorting; 3, parameters; 4, block; 5, identifier:self; 6, identifier:query; 7, expression_statement; 8, expression_statement; 9, comment:# Sort on; 10, expression_statement; 11, expression_statement; 12, expression_statement; 13, if_statement; 14, return_statement; 15, comment:"""Resolves the sorting criteria for the given query
          """; 16, assignment; 17, assignment; 18, assignment; 19, assignment; 20, identifier:sort_on; 21, block; 22, identifier:sorting; 23, identifier:sorting; 24, dictionary; 25, identifier:sort_on; 26, call; 27, identifier:sort_on; 28, boolean_operator; 29, identifier:sort_on; 30, boolean_operator; 31, expression_statement; 32, comment:# Sort order; 33, expression_statement; 34, expression_statement; 35, if_statement; 36, comment:# Sort limit; 37, expression_statement; 38, if_statement; 39, attribute; 40, argument_list; 41, identifier:sort_on; 42, call; 43, boolean_operator; 44, identifier:sort_on; 45, assignment; 46, assignment; 47, assignment; 48, comparison_operator:sort_order in ["desc", "reverse", "rev", "descending"]; 49, block; 50, else_clause; 51, assignment; 52, identifier:sort_limit; 53, block; 54, identifier:query; 55, identifier:get; 56, string:"sidx"; 57, None; 58, attribute; 59, argument_list; 60, comparison_operator:sort_on == "Title"; 61, string:"sortable_title"; 62, subscript; 63, identifier:sort_on; 64, identifier:sort_order; 65, call; 66, identifier:sort_order; 67, boolean_operator; 68, identifier:sort_order; 69, list; 70, expression_statement; 71, block; 72, identifier:sort_limit; 73, call; 74, expression_statement; 75, identifier:query; 76, identifier:get; 77, string:"sort_on"; 78, None; 79, identifier:sort_on; 80, string:"Title"; 81, identifier:sorting; 82, string:"sort_on"; 83, attribute; 84, argument_list; 85, identifier:sort_order; 86, call; 87, string:"desc"; 88, string:"reverse"; 89, string:"rev"; 90, string:"descending"; 91, assignment; 92, expression_statement; 93, attribute; 94, argument_list; 95, assignment; 96, identifier:query; 97, identifier:get; 98, string:"sord"; 99, None; 100, attribute; 101, argument_list; 102, subscript; 103, string:"descending"; 104, assignment; 105, identifier:api; 106, identifier:to_int; 107, call; 108, keyword_argument; 109, subscript; 110, identifier:sort_limit; 111, identifier:query; 112, identifier:get; 113, string:"sort_order"; 114, None; 115, identifier:sorting; 116, string:"sort_order"; 117, subscript; 118, string:"ascending"; 119, attribute; 120, argument_list; 121, identifier:default; 122, integer:30; 123, identifier:sorting; 124, string:"sort_limit"; 125, identifier:sorting; 126, string:"sort_order"; 127, identifier:query; 128, identifier:get; 129, string:"limit"; 130, integer:30
code: def resolve_sorting(self, query):
          """Resolves the sorting criteria for the given query
          """
          sorting = {}
  
          # Sort on
          sort_on = query.get("sidx", None)
          sort_on = sort_on or query.get("sort_on", None)
          sort_on = sort_on == "Title" and "sortable_title" or sort_on
          if sort_on:
              sorting["sort_on"] = sort_on
  
              # Sort order
              sort_order = query.get("sord", None)
              sort_order = sort_order or query.get("sort_order", None)
              if sort_order in ["desc", "reverse", "rev", "descending"]:
                  sorting["sort_order"] = "descending"
              else:
                  sorting["sort_order"] = "ascending"
  
              # Sort limit
              sort_limit = api.to_int(query.get("limit", 30), default=30)
              if sort_limit:
                  sorting["sort_limit"] = sort_limit
  
          return sorting