nodes: 0, module; 1, function_definition; 2, function_name:get_runs; 3, parameters; 4, block; 5, expression_statement; 6, expression_statement; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, expression_statement; 12, expression_statement; 13, expression_statement; 14, if_statement; 15, expression_statement; 16, comment:# records_total should be the total size of the records in the database,; 17, comment:# not what was returned; 18, expression_statement; 19, expression_statement; 20, return_statement; 21, comment:"""Get all runs, sort it and return a response."""; 22, assignment; 23, assignment; 24, assignment; 25, assignment; 26, assignment; 27, assignment; 28, assignment; 29, assignment; 30, comparison_operator:order_column is not None; 31, block; 32, assignment; 33, assignment; 34, assignment; 35, call; 36, identifier:data; 37, subscript; 38, identifier:draw; 39, call; 40, identifier:start; 41, call; 42, identifier:length; 43, call; 44, identifier:length; 45, conditional_expression:length if length >= 0 else None; 46, identifier:order_column; 47, call; 48, identifier:order_dir; 49, call; 50, identifier:query; 51, call; 52, identifier:order_column; 53, None; 54, expression_statement; 55, if_statement; 56, identifier:runs; 57, call; 58, identifier:records_total; 59, call; 60, identifier:records_filtered; 61, call; 62, identifier:Response; 63, argument_list; 64, attribute; 65, string:"data"; 66, identifier:parse_int_arg; 67, argument_list; 68, identifier:parse_int_arg; 69, argument_list; 70, identifier:parse_int_arg; 71, argument_list; 72, identifier:length; 73, comparison_operator:length >= 0; 74, None; 75, attribute; 76, argument_list; 77, attribute; 78, argument_list; 79, identifier:parse_query_filter; 80, argument_list; 81, assignment; 82, comparison_operator:order_column == "hostname"; 83, block; 84, attribute; 85, argument_list; 86, attribute; 87, argument_list; 88, attribute; 89, argument_list; 90, call; 91, keyword_argument; 92, identifier:current_app; 93, identifier:config; 94, string:"draw"; 95, integer:1; 96, string:"start"; 97, integer:0; 98, string:"length"; 99, unary_operator; 100, identifier:length; 101, integer:0; 102, attribute; 103, identifier:get; 104, string:"order[0][column]"; 105, attribute; 106, identifier:get; 107, string:"order[0][dir]"; 108, identifier:order_column; 109, line_continuation:\; 110, call; 111, identifier:order_column; 112, string:"hostname"; 113, expression_statement; 114, call; 115, identifier:get_runs; 116, keyword_argument; 117, keyword_argument; 118, keyword_argument; 119, keyword_argument; 120, keyword_argument; 121, identifier:runs; 122, identifier:count; 123, identifier:runs; 124, identifier:count; 125, identifier:render_template; 126, argument_list; 127, identifier:mimetype; 128, string:"application/json"; 129, integer:1; 130, identifier:request; 131, identifier:args; 132, identifier:request; 133, identifier:args; 134, attribute; 135, argument_list; 136, assignment; 137, attribute; 138, argument_list; 139, identifier:start; 140, identifier:start; 141, identifier:limit; 142, identifier:length; 143, identifier:sort_by; 144, identifier:order_column; 145, identifier:sort_direction; 146, identifier:order_dir; 147, identifier:query; 148, identifier:query; 149, string:"api/runs.js"; 150, keyword_argument; 151, keyword_argument; 152, keyword_argument; 153, keyword_argument; 154, attribute; 155, identifier:get; 156, binary_operator:"columns[%d][name]" % int(order_column); 157, identifier:order_column; 158, string:"host.hostname"; 159, identifier:data; 160, identifier:get_run_dao; 161, identifier:runs; 162, identifier:runs; 163, identifier:draw; 164, identifier:draw; 165, identifier:recordsTotal; 166, identifier:records_total; 167, identifier:recordsFiltered; 168, identifier:records_filtered; 169, identifier:request; 170, identifier:args; 171, string:"columns[%d][name]"; 172, call; 173, identifier:int; 174, argument_list; 175, identifier:order_column
code: def get_runs():
      """Get all runs, sort it and return a response."""
      data = current_app.config["data"]
      draw = parse_int_arg("draw", 1)
      start = parse_int_arg("start", 0)
      length = parse_int_arg("length", -1)
      length = length if length >= 0 else None
      order_column = request.args.get("order[0][column]")
      order_dir = request.args.get("order[0][dir]")
  
      query = parse_query_filter()
  
      if order_column is not None:
          order_column = \
              request.args.get("columns[%d][name]" % int(order_column))
          if order_column == "hostname":
              order_column = "host.hostname"
  
      runs = data.get_run_dao().get_runs(
          start=start, limit=length,
          sort_by=order_column, sort_direction=order_dir, query=query)
      # records_total should be the total size of the records in the database,
      # not what was returned
      records_total = runs.count()
      records_filtered = runs.count()
      return Response(render_template(
          "api/runs.js", runs=runs,
          draw=draw, recordsTotal=records_total,
          recordsFiltered=records_filtered),
          mimetype="application/json")